diff --git a/bin/build_package.js b/bin/build_package.ts similarity index 71% rename from bin/build_package.js rename to bin/build_package.ts index 01bcf80c436..08c079b56d2 100644 --- a/bin/build_package.js +++ b/bin/build_package.ts @@ -2,13 +2,13 @@ * This file is used to compile the assets from an UX package. */ -const { parseArgs } = require('node:util'); -const path = require('node:path'); -const fs = require('node:fs'); -const glob = require('glob'); -const rollup = require('rollup'); -const LightningCSS = require('lightningcss'); -const { getRollupConfiguration } = require('./rollup'); +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import { parseArgs } from 'node:util'; +import * as LightningCSS from 'lightningcss'; +import * as rollup from 'rollup'; +import { globSync } from 'tinyglobby'; +import { getRollupConfiguration } from './rollup.ts'; const args = parseArgs({ allowPositionals: true, @@ -34,7 +34,7 @@ async function main() { process.exit(1); } - const packageData = require(path.join(packageRoot, 'package.json')); + const packageData = await import(path.join(packageRoot, 'package.json'), {with: { type: 'json'}}); const packageName = packageData.name; const srcDir = path.join(packageRoot, 'src'); const distDir = path.join(packageRoot, 'dist'); @@ -51,7 +51,7 @@ async function main() { } const inputScriptFiles = [ - ...glob.sync(path.join(srcDir, '*controller.ts')), + ...globSync(path.join(srcDir, '*controller.ts')), ...(['@symfony/ux-react', '@symfony/ux-vue', '@symfony/ux-svelte'].includes(packageName) ? [path.join(srcDir, 'loader.ts'), path.join(srcDir, 'components.ts')] : []), @@ -62,12 +62,10 @@ async function main() { const inputStyleFile = packageData.config?.css_source; const buildCss = async () => { - const inputStyleFileDist = inputStyleFile - ? path.resolve(distDir, `${path.basename(inputStyleFile, '.css')}.min.css`) - : undefined; if (!inputStyleFile) { return; } + const inputStyleFileDist = path.resolve(distDir, `${path.basename(inputStyleFile, '.css')}.min.css`); console.log('Minifying CSS...'); const css = await fs.promises.readFile(inputStyleFile, 'utf-8'); @@ -82,34 +80,41 @@ async function main() { if (inputScriptFiles.length === 0) { console.error( - `No input files found for package "${packageName}" (directory "${packageRoot}").\nEnsure you have at least a file matching the pattern "src/*_controller.ts", or manually specify input files in "${__filename}" file.` + `No input files found for package "${packageName}" (directory "${packageRoot}").\nEnsure you have at least a file matching the pattern "src/*_controller.ts", or manually specify input files in "${import.meta.filename}" file.` ); process.exit(1); } - const rollupConfig = getRollupConfiguration({ packageRoot, inputFiles: inputScriptFiles, isWatch }); + const rollupConfig = getRollupConfiguration({ + packageRoot, + inputFiles: inputScriptFiles, + isWatch, + additionalPlugins: [ + ...(isWatch && inputStyleFile + ? [ + { + name: 'watcher', + buildStart(this: rollup.PluginContext) { + this.addWatchFile(inputStyleFile); + }, + }, + ] + : []), + ], + }); if (isWatch) { console.log( `Watching for JavaScript${inputStyleFile ? ' and CSS' : ''} files modifications in "${srcDir}" directory...` ); - if (inputStyleFile) { - rollupConfig.plugins = (rollupConfig.plugins || []).concat({ - name: 'watcher', - buildStart() { - this.addWatchFile(inputStyleFile); - }, - }); - } - const watcher = rollup.watch(rollupConfig); watcher.on('event', (event) => { if (event.code === 'ERROR') { console.error('Error during build:', event.error); } - if (event.result) { + if ((event.code === 'BUNDLE_END' || event.code === 'ERROR') && event.result) { event.result.close(); } }); @@ -126,6 +131,13 @@ async function main() { console.log(`Building JavaScript files from ${packageName} package...`); const start = Date.now(); + if (typeof rollupConfig.output === 'undefined' || Array.isArray(rollupConfig.output)) { + console.error( + `The rollup configuration for package "${packageName}" does not contain a valid output configuration.` + ); + process.exit(1); + } + const bundle = await rollup.rollup(rollupConfig); await bundle.write(rollupConfig.output); diff --git a/bin/rollup.js b/bin/rollup.js deleted file mode 100644 index 62b0010457b..00000000000 --- a/bin/rollup.js +++ /dev/null @@ -1,136 +0,0 @@ -const fs = require('node:fs'); -const path = require('node:path'); -const resolve = require('@rollup/plugin-node-resolve'); -const commonjs = require('@rollup/plugin-commonjs'); -const typescript = require('@rollup/plugin-typescript'); -const glob = require('glob'); - -/** - * Guarantees that any files imported from a peer dependency are treated as an external. - * - * For example, if we import `chart.js/auto`, that would not normally - * match the "chart.js" we pass to the "externals" config. This plugin - * catches that case and adds it as an external. - * - * Inspired by https://github.com/oat-sa/rollup-plugin-wildcard-external - */ -const wildcardExternalsPlugin = (peerDependencies) => ({ - name: 'wildcard-externals', - resolveId(source, importer) { - if (importer) { - let matchesExternal = false; - peerDependencies.forEach((peerDependency) => { - if (source.includes(`/${peerDependency}/`)) { - matchesExternal = true; - } - }); - - if (matchesExternal) { - return { - id: source, - external: true, - moduleSideEffects: true, - }; - } - } - - return null; // other ids should be handled as usually - }, -}); - -/** - * Moves the generated TypeScript declaration files to the correct location. - * - * This could probably be configured in the TypeScript plugin. - */ -const moveTypescriptDeclarationsPlugin = (packageRoot) => ({ - name: 'move-ts-declarations', - writeBundle: async () => { - const isBridge = packageRoot.includes('src/Bridge'); - const globPattern = path.join('dist', '**', 'assets', 'src', '**/*.d.ts'); - const files = glob.sync(globPattern); - - files.forEach((file) => { - const relativePath = file; - // a bit odd, but remove first 7 or 4 directories, which will leave only the relative path to the file - // ex: dist/Chartjs/assets/src/controller.d.ts' => 'dist/controller.d.ts' - const targetFile = relativePath.replace( - `${relativePath - .split('/') - .slice(1, isBridge ? 7 : 4) - .join('/')}/`, - '' - ); - if (!fs.existsSync(path.dirname(targetFile))) { - fs.mkdirSync(path.dirname(targetFile), { recursive: true }); - } - fs.renameSync(file, targetFile); - }); - }, -}); - -/** - * @param {String} packageRoot - * @param {Array} inputFiles - * @param {Boolean} isWatch - */ -function getRollupConfiguration({ packageRoot, inputFiles, isWatch }) { - const packagePath = path.join(packageRoot, 'package.json'); - const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8')); - const peerDependencies = [ - '@hotwired/stimulus', - ...(packageData.peerDependencies ? Object.keys(packageData.peerDependencies) : []), - ]; - - inputFiles.forEach((file) => { - // custom handling for StimulusBundle - if (file.includes('StimulusBundle/assets/src/loader.ts')) { - peerDependencies.push('./controllers.js'); - } - - // React, Vue - if (file.includes('assets/src/loader.ts')) { - peerDependencies.push('./components.js'); - } - }); - - const outDir = path.join(packageRoot, 'dist'); - - return { - input: inputFiles, - output: { - dir: outDir, - entryFileNames: '[name].js', - format: 'esm', - }, - external: peerDependencies, - plugins: [ - resolve(), - typescript({ - filterRoot: '.', - tsconfig: path.join(__dirname, '..', 'tsconfig.json'), - noEmitOnError: !isWatch, - include: [ - 'src/**/*.ts', - // TODO: Remove for the next major release - // "@rollup/plugin-typescript" v11.0.0 fixed an issue (https://github.com/rollup/plugins/pull/1310) that - // cause a breaking change for UX React users, the dist file requires "react-dom/client" instead of "react-dom" - // and it will break for users using the Symfony AssetMapper without Symfony Flex (for automatic "importmap.php" upgrade). - '**/node_modules/react-dom/client.js', - ], - compilerOptions: { - outDir: outDir, - declaration: true, - emitDeclarationOnly: true, - }, - }), - commonjs(), - wildcardExternalsPlugin(peerDependencies), - moveTypescriptDeclarationsPlugin(packageRoot), - ], - }; -} - -module.exports = { - getRollupConfiguration, -}; diff --git a/bin/rollup.ts b/bin/rollup.ts new file mode 100644 index 00000000000..398878628fc --- /dev/null +++ b/bin/rollup.ts @@ -0,0 +1,143 @@ +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import commonjs from '@rollup/plugin-commonjs'; +import resolve from '@rollup/plugin-node-resolve'; +import typescript from '@rollup/plugin-typescript'; +import type { Plugin, RollupOptions } from 'rollup'; +import { globSync } from 'tinyglobby'; + +/** + * Guarantees that any files imported from a peer dependency are treated as an external. + * + * For example, if we import `chart.js/auto`, that would not normally + * match the "chart.js" we pass to the "externals" config. This plugin + * catches that case and adds it as an external. + * + * Inspired by https://github.com/oat-sa/rollup-plugin-wildcard-external + */ +function wildcardExternalsPlugin(peerDependencies: Array): Plugin { + return { + name: 'wildcard-externals', + resolveId(source, importer) { + if (importer) { + let matchesExternal = false; + peerDependencies.forEach((peerDependency) => { + if (source.includes(`/${peerDependency}/`)) { + matchesExternal = true; + } + }); + + if (matchesExternal) { + return { + id: source, + external: true, + moduleSideEffects: true, + }; + } + } + + return null; // other ids should be handled as usually + }, + }; +} + +/** + * Moves the generated TypeScript declaration files to the correct location. + * + * This could probably be configured in the TypeScript plugin. + */ +function moveTypescriptDeclarationsPlugin(packageRoot: string): Plugin { + return { + name: 'move-ts-declarations', + writeBundle: async () => { + const isBridge = packageRoot.includes('src/Bridge'); + const globPattern = path.join('dist', '**', 'assets', 'src', '**/*.d.ts'); + const files = globSync(globPattern); + + files.forEach((file) => { + const relativePath = file; + // a bit odd, but remove first 7 or 4 directories, which will leave only the relative path to the file + // ex: dist/Chartjs/assets/src/controller.d.ts' => 'dist/controller.d.ts' + const targetFile = relativePath.replace( + `${relativePath + .split('/') + .slice(1, isBridge ? 7 : 4) + .join('/')}/`, + '' + ); + if (!fs.existsSync(path.dirname(targetFile))) { + fs.mkdirSync(path.dirname(targetFile), { recursive: true }); + } + fs.renameSync(file, targetFile); + }); + }, + }; +} + +export function getRollupConfiguration({ + packageRoot, + inputFiles, + isWatch, + additionalPlugins, +}: { + packageRoot: string; + inputFiles: string[]; + isWatch: boolean; + additionalPlugins: Array; +}): RollupOptions { + const packagePath = path.join(packageRoot, 'package.json'); + const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8')); + const peerDependencies = [ + '@hotwired/stimulus', + ...(packageData.peerDependencies ? Object.keys(packageData.peerDependencies) : []), + ]; + + inputFiles.forEach((file) => { + // custom handling for StimulusBundle + if (file.includes('StimulusBundle/assets/src/loader.ts')) { + peerDependencies.push('./controllers.js'); + } + + // React, Vue + if (file.includes('assets/src/loader.ts')) { + peerDependencies.push('./components.js'); + } + }); + + const outDir = path.join(packageRoot, 'dist'); + + return { + input: inputFiles, + output: { + dir: outDir, + entryFileNames: '[name].js', + format: 'esm', + }, + external: peerDependencies, + plugins: [ + resolve(), + typescript({ + filterRoot: '.', + tsconfig: path.join(import.meta.dirname, '..', 'tsconfig.packages.json'), + noEmitOnError: !isWatch, + include: [ + 'src/**/*.ts', + // TODO: Remove for the next major release + // "@rollup/plugin-typescript" v11.0.0 fixed an issue (https://github.com/rollup/plugins/pull/1310) that + // cause a breaking change for UX React users, the dist file requires "react-dom/client" instead of "react-dom" + // and it will break for users using the Symfony AssetMapper without Symfony Flex (for automatic "importmap.php" upgrade). + '**/node_modules/react-dom/client.js', + ], + compilerOptions: { + outDir: outDir, + declaration: true, + emitDeclarationOnly: true, + }, + }), + commonjs(), + wildcardExternalsPlugin(peerDependencies), + moveTypescriptDeclarationsPlugin(packageRoot), + ...additionalPlugins, + ], + }; +} diff --git a/package.json b/package.json index 4e5098eb2a5..07551862263 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "private": true, "packageManager": "yarn@4.5.0", + "type": "module", "workspaces": [ "src/*/assets", "src/*/src/Bridge/*/assets" @@ -21,11 +22,14 @@ "@rollup/plugin-node-resolve": "^15.3.0", "@rollup/plugin-typescript": "^11.1.6", "@symfony/stimulus-testing": "^2.0.1", + "@types/node": "^22.6.0", "@vitest/browser": "^2.1.1", "lightningcss": "^1.28.2", "playwright": "^1.47.0", "rollup": "^4.22.5", + "tinyglobby": "^0.2.14", "tslib": "^2.6.3", + "tsx": "^4.20.3", "typescript": "^5.5.4", "vitest": "^2.1.1" }, diff --git a/src/Autocomplete/assets/package.json b/src/Autocomplete/assets/package.json index 530b1294e08..4d3a280daad 100644 --- a/src/Autocomplete/assets/package.json +++ b/src/Autocomplete/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/controller.js", "types": "dist/controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Chartjs/assets/package.json b/src/Chartjs/assets/package.json index 261a8f7bc40..6b92496eaed 100644 --- a/src/Chartjs/assets/package.json +++ b/src/Chartjs/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/controller.js", "types": "dist/controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Cropperjs/assets/package.json b/src/Cropperjs/assets/package.json index fad35a12d19..2987975070f 100644 --- a/src/Cropperjs/assets/package.json +++ b/src/Cropperjs/assets/package.json @@ -18,8 +18,8 @@ "css_source": "src/style.css" }, "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Dropzone/assets/package.json b/src/Dropzone/assets/package.json index 84d27abe791..a841d93585a 100644 --- a/src/Dropzone/assets/package.json +++ b/src/Dropzone/assets/package.json @@ -18,8 +18,8 @@ "css_source": "src/style.css" }, "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/LazyImage/assets/package.json b/src/LazyImage/assets/package.json index 64c6eca7354..3eb559bb70d 100644 --- a/src/LazyImage/assets/package.json +++ b/src/LazyImage/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/controller.js", "types": "dist/controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/LiveComponent/assets/package.json b/src/LiveComponent/assets/package.json index 7da41ec066f..57cab1f9362 100644 --- a/src/LiveComponent/assets/package.json +++ b/src/LiveComponent/assets/package.json @@ -20,8 +20,8 @@ "css_source": "styles/live.css" }, "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Map/assets/package.json b/src/Map/assets/package.json index b4b8e7e50d1..a6d449a0fae 100644 --- a/src/Map/assets/package.json +++ b/src/Map/assets/package.json @@ -19,8 +19,8 @@ "main": "dist/abstract_map_controller.js", "types": "dist/abstract_map_controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Map/src/Bridge/Google/assets/package.json b/src/Map/src/Bridge/Google/assets/package.json index 4a225bfa385..06b4a50ae47 100644 --- a/src/Map/src/Bridge/Google/assets/package.json +++ b/src/Map/src/Bridge/Google/assets/package.json @@ -17,8 +17,8 @@ "main": "dist/map_controller.js", "types": "dist/map_controller.d.ts", "scripts": { - "build": "node ../../../../../../bin/build_package.js .", - "watch": "node ../../../../../../bin/build_package.js . --watch", + "build": "tsx ../../../../../../bin/build_package.ts .", + "watch": "tsx ../../../../../../bin/build_package.ts . --watch", "test": "../../../../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Map/src/Bridge/Leaflet/assets/package.json b/src/Map/src/Bridge/Leaflet/assets/package.json index 7fd87f82933..f18cee005c9 100644 --- a/src/Map/src/Bridge/Leaflet/assets/package.json +++ b/src/Map/src/Bridge/Leaflet/assets/package.json @@ -17,8 +17,8 @@ "main": "dist/map_controller.js", "types": "dist/map_controller.d.ts", "scripts": { - "build": "node ../../../../../../bin/build_package.js .", - "watch": "node ../../../../../../bin/build_package.js . --watch", + "build": "tsx ../../../../../../bin/build_package.ts .", + "watch": "tsx ../../../../../../bin/build_package.ts . --watch", "test": "../../../../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Notify/assets/package.json b/src/Notify/assets/package.json index 3da290b43c4..378d7fb5f4b 100644 --- a/src/Notify/assets/package.json +++ b/src/Notify/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/controller.js", "types": "dist/controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/React/assets/package.json b/src/React/assets/package.json index f77da378485..e9c388bdf2b 100644 --- a/src/React/assets/package.json +++ b/src/React/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/register_controller.js", "types": "dist/register_controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/StimulusBundle/assets/package.json b/src/StimulusBundle/assets/package.json index ec09f8b08e6..7047a0c25c5 100644 --- a/src/StimulusBundle/assets/package.json +++ b/src/StimulusBundle/assets/package.json @@ -15,8 +15,8 @@ ], "main": "dist/loader.js", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Svelte/assets/package.json b/src/Svelte/assets/package.json index 31f54f1e512..0fc7f86b6c8 100644 --- a/src/Svelte/assets/package.json +++ b/src/Svelte/assets/package.json @@ -14,8 +14,8 @@ ], "main": "dist/register_controller.js", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Swup/assets/package.json b/src/Swup/assets/package.json index 6d4fb7add55..7cc36d53998 100644 --- a/src/Swup/assets/package.json +++ b/src/Swup/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/controller.js", "types": "dist/controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/TogglePassword/assets/package.json b/src/TogglePassword/assets/package.json index bd6f7a18f7f..25631fc7157 100644 --- a/src/TogglePassword/assets/package.json +++ b/src/TogglePassword/assets/package.json @@ -18,8 +18,8 @@ "css_source": "src/style.css" }, "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Translator/assets/package.json b/src/Translator/assets/package.json index 6c7b2619df2..97bda05e1da 100644 --- a/src/Translator/assets/package.json +++ b/src/Translator/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/translator_controller.js", "types": "dist/translator_controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Turbo/assets/package.json b/src/Turbo/assets/package.json index 3e46482a869..301f6d3aa95 100644 --- a/src/Turbo/assets/package.json +++ b/src/Turbo/assets/package.json @@ -20,8 +20,8 @@ "main": "dist/turbo_controller.js", "types": "dist/turbo_controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Typed/assets/package.json b/src/Typed/assets/package.json index 240742a1430..540f85f27a3 100644 --- a/src/Typed/assets/package.json +++ b/src/Typed/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/controller.js", "types": "dist/controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/src/Vue/assets/package.json b/src/Vue/assets/package.json index 4a349d711ec..38258538d14 100644 --- a/src/Vue/assets/package.json +++ b/src/Vue/assets/package.json @@ -15,8 +15,8 @@ "main": "dist/register_controller.js", "types": "dist/register_controller.d.ts", "scripts": { - "build": "node ../../../bin/build_package.js .", - "watch": "node ../../../bin/build_package.js . --watch", + "build": "tsx ../../../bin/build_package.ts .", + "watch": "tsx ../../../bin/build_package.ts . --watch", "test": "../../../bin/test_package.sh .", "check": "biome check", "ci": "biome ci" diff --git a/tsconfig.json b/tsconfig.json index c57ddd9188d..d37c70076c2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,11 @@ { + "//": "This tsconfig.json is used for internal tools and scripts", "compilerOptions": { - "lib": ["dom", "es2015"], - "module": "es2015", + "allowImportingTsExtensions": true, + "composite": true, + "module": "esnext", "moduleResolution": "node", - "noUnusedLocals": true, - "rootDir": "src", - "strict": true, - "strictPropertyInitialization": false, - "target": "es2021", - "removeComments": true, - "outDir": "types", - "baseUrl": ".", - "noEmit": false, - "declaration": false, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "jsx": "react" + "resolveJsonModule": true }, - "exclude": ["src/*/assets/dist", "src/*/src/Bridge/*/assets/dist"], - "include": [ - "src/*/assets/src", - "src/*/assets/test", - "src/*/src/Bridge/*/assets/src", - "src/*/src/Bridge/*/assets/test" - ] + "include": ["bin/**/*.ts"] } diff --git a/tsconfig.packages.json b/tsconfig.packages.json new file mode 100644 index 00000000000..7b2c6747dc4 --- /dev/null +++ b/tsconfig.packages.json @@ -0,0 +1,28 @@ +{ + "//": "This file is used to compile UX packages for use in the browser.", + "compilerOptions": { + "lib": ["dom", "es2015"], + "module": "es2015", + "moduleResolution": "node", + "noUnusedLocals": true, + "rootDir": "src", + "strict": true, + "strictPropertyInitialization": false, + "target": "es2021", + "removeComments": true, + "outDir": "types", + "baseUrl": ".", + "noEmit": false, + "declaration": false, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "jsx": "react" + }, + "exclude": ["src/*/assets/dist", "src/*/src/Bridge/*/assets/dist"], + "include": [ + "src/*/assets/src", + "src/*/assets/test", + "src/*/src/Bridge/*/assets/src", + "src/*/src/Bridge/*/assets/test" + ] +} diff --git a/yarn.lock b/yarn.lock index 200ffc18b69..64da1437d85 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1642,6 +1642,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/aix-ppc64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/aix-ppc64@npm:0.25.5" + conditions: os=aix & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/android-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-arm64@npm:0.21.5" @@ -1649,6 +1656,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/android-arm64@npm:0.25.5" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/android-arm@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-arm@npm:0.21.5" @@ -1656,6 +1670,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/android-arm@npm:0.25.5" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@esbuild/android-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/android-x64@npm:0.21.5" @@ -1663,6 +1684,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/android-x64@npm:0.25.5" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + "@esbuild/darwin-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/darwin-arm64@npm:0.21.5" @@ -1670,6 +1698,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-arm64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/darwin-arm64@npm:0.25.5" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/darwin-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/darwin-x64@npm:0.21.5" @@ -1677,6 +1712,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/darwin-x64@npm:0.25.5" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@esbuild/freebsd-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/freebsd-arm64@npm:0.21.5" @@ -1684,6 +1726,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-arm64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/freebsd-arm64@npm:0.25.5" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/freebsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/freebsd-x64@npm:0.21.5" @@ -1691,6 +1740,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/freebsd-x64@npm:0.25.5" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/linux-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-arm64@npm:0.21.5" @@ -1698,6 +1754,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-arm64@npm:0.25.5" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/linux-arm@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-arm@npm:0.21.5" @@ -1705,6 +1768,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-arm@npm:0.25.5" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + "@esbuild/linux-ia32@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-ia32@npm:0.21.5" @@ -1712,6 +1782,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ia32@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-ia32@npm:0.25.5" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/linux-loong64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-loong64@npm:0.21.5" @@ -1719,6 +1796,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-loong64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-loong64@npm:0.25.5" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + "@esbuild/linux-mips64el@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-mips64el@npm:0.21.5" @@ -1726,6 +1810,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-mips64el@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-mips64el@npm:0.25.5" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + "@esbuild/linux-ppc64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-ppc64@npm:0.21.5" @@ -1733,6 +1824,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ppc64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-ppc64@npm:0.25.5" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/linux-riscv64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-riscv64@npm:0.21.5" @@ -1740,6 +1838,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-riscv64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-riscv64@npm:0.25.5" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + "@esbuild/linux-s390x@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-s390x@npm:0.21.5" @@ -1747,6 +1852,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-s390x@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-s390x@npm:0.25.5" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + "@esbuild/linux-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/linux-x64@npm:0.21.5" @@ -1754,6 +1866,20 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/linux-x64@npm:0.25.5" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/netbsd-arm64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/netbsd-arm64@npm:0.25.5" + conditions: os=netbsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/netbsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/netbsd-x64@npm:0.21.5" @@ -1761,6 +1887,20 @@ __metadata: languageName: node linkType: hard +"@esbuild/netbsd-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/netbsd-x64@npm:0.25.5" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + +"@esbuild/openbsd-arm64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/openbsd-arm64@npm:0.25.5" + conditions: os=openbsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/openbsd-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/openbsd-x64@npm:0.21.5" @@ -1768,6 +1908,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/openbsd-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/openbsd-x64@npm:0.25.5" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/sunos-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/sunos-x64@npm:0.21.5" @@ -1775,6 +1922,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/sunos-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/sunos-x64@npm:0.25.5" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + "@esbuild/win32-arm64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-arm64@npm:0.21.5" @@ -1782,6 +1936,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-arm64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/win32-arm64@npm:0.25.5" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/win32-ia32@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-ia32@npm:0.21.5" @@ -1789,6 +1950,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-ia32@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/win32-ia32@npm:0.25.5" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/win32-x64@npm:0.21.5": version: 0.21.5 resolution: "@esbuild/win32-x64@npm:0.21.5" @@ -1796,6 +1964,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-x64@npm:0.25.5": + version: 0.25.5 + resolution: "@esbuild/win32-x64@npm:0.25.5" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@formatjs/ecma402-abstract@npm:1.18.2": version: 1.18.2 resolution: "@formatjs/ecma402-abstract@npm:1.18.2" @@ -3367,6 +3542,15 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^22.6.0": + version: 22.15.33 + resolution: "@types/node@npm:22.15.33" + dependencies: + undici-types: "npm:~6.21.0" + checksum: 10c0/ee040c29c891aa37fffc27d04a8529318c391356346933646b7692eaf62236831ad532f6ebaf43ebd6a2ef1f0f091860d8a0a83a4e3c5a4f66d37aa1b2c99f31 + languageName: node + linkType: hard + "@types/normalize-package-data@npm:^2.4.0": version: 2.4.1 resolution: "@types/normalize-package-data@npm:2.4.1" @@ -5123,6 +5307,92 @@ __metadata: languageName: node linkType: hard +"esbuild@npm:~0.25.0": + version: 0.25.5 + resolution: "esbuild@npm:0.25.5" + dependencies: + "@esbuild/aix-ppc64": "npm:0.25.5" + "@esbuild/android-arm": "npm:0.25.5" + "@esbuild/android-arm64": "npm:0.25.5" + "@esbuild/android-x64": "npm:0.25.5" + "@esbuild/darwin-arm64": "npm:0.25.5" + "@esbuild/darwin-x64": "npm:0.25.5" + "@esbuild/freebsd-arm64": "npm:0.25.5" + "@esbuild/freebsd-x64": "npm:0.25.5" + "@esbuild/linux-arm": "npm:0.25.5" + "@esbuild/linux-arm64": "npm:0.25.5" + "@esbuild/linux-ia32": "npm:0.25.5" + "@esbuild/linux-loong64": "npm:0.25.5" + "@esbuild/linux-mips64el": "npm:0.25.5" + "@esbuild/linux-ppc64": "npm:0.25.5" + "@esbuild/linux-riscv64": "npm:0.25.5" + "@esbuild/linux-s390x": "npm:0.25.5" + "@esbuild/linux-x64": "npm:0.25.5" + "@esbuild/netbsd-arm64": "npm:0.25.5" + "@esbuild/netbsd-x64": "npm:0.25.5" + "@esbuild/openbsd-arm64": "npm:0.25.5" + "@esbuild/openbsd-x64": "npm:0.25.5" + "@esbuild/sunos-x64": "npm:0.25.5" + "@esbuild/win32-arm64": "npm:0.25.5" + "@esbuild/win32-ia32": "npm:0.25.5" + "@esbuild/win32-x64": "npm:0.25.5" + dependenciesMeta: + "@esbuild/aix-ppc64": + optional: true + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-arm64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-arm64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: 10c0/aba8cbc11927fa77562722ed5e95541ce2853f67ad7bdc40382b558abc2e0ec57d92ffb820f082ba2047b4ef9f3bc3da068cdebe30dfd3850cfa3827a78d604e + languageName: node + linkType: hard + "escalade@npm:^3.1.1": version: 3.1.1 resolution: "escalade@npm:3.1.1" @@ -5382,6 +5652,18 @@ __metadata: languageName: node linkType: hard +"fdir@npm:^6.4.4": + version: 6.4.6 + resolution: "fdir@npm:6.4.6" + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + checksum: 10c0/45b559cff889934ebb8bc498351e5acba40750ada7e7d6bde197768d2fa67c149be8ae7f8ff34d03f4e1eb20f2764116e56440aaa2f6689e9a4aa7ef06acafe9 + languageName: node + linkType: hard + "fill-range@npm:^4.0.0": version: 4.0.0 resolution: "fill-range@npm:4.0.0" @@ -5593,6 +5875,15 @@ __metadata: languageName: node linkType: hard +"get-tsconfig@npm:^4.7.5": + version: 4.10.1 + resolution: "get-tsconfig@npm:4.10.1" + dependencies: + resolve-pkg-maps: "npm:^1.0.0" + checksum: 10c0/7f8e3dabc6a49b747920a800fb88e1952fef871cdf51b79e98db48275a5de6cdaf499c55ee67df5fa6fe7ce65f0063e26de0f2e53049b408c585aa74d39ffa21 + languageName: node + linkType: hard + "get-value@npm:^2.0.3, get-value@npm:^2.0.6": version: 2.0.6 resolution: "get-value@npm:2.0.6" @@ -8206,6 +8497,13 @@ __metadata: languageName: node linkType: hard +"picomatch@npm:^4.0.2": + version: 4.0.2 + resolution: "picomatch@npm:4.0.2" + checksum: 10c0/7c51f3ad2bb42c776f49ebf964c644958158be30d0a510efd5a395e8d49cb5acfed5b82c0c5b365523ce18e6ab85013c9ebe574f60305892ec3fa8eee8304ccc + languageName: node + linkType: hard + "pirates@npm:^4.0.1": version: 4.0.5 resolution: "pirates@npm:4.0.5" @@ -8605,6 +8903,13 @@ __metadata: languageName: node linkType: hard +"resolve-pkg-maps@npm:^1.0.0": + version: 1.0.0 + resolution: "resolve-pkg-maps@npm:1.0.0" + checksum: 10c0/fb8f7bbe2ca281a73b7ef423a1cbc786fb244bd7a95cbe5c3fba25b27d327150beca8ba02f622baea65919a57e061eb5005204daa5f93ed590d9b77463a567ab + languageName: node + linkType: hard + "resolve-url@npm:^0.2.1": version: 0.2.1 resolution: "resolve-url@npm:0.2.1" @@ -8802,11 +9107,14 @@ __metadata: "@rollup/plugin-node-resolve": "npm:^15.3.0" "@rollup/plugin-typescript": "npm:^11.1.6" "@symfony/stimulus-testing": "npm:^2.0.1" + "@types/node": "npm:^22.6.0" "@vitest/browser": "npm:^2.1.1" lightningcss: "npm:^1.28.2" playwright: "npm:^1.47.0" rollup: "npm:^4.22.5" + tinyglobby: "npm:^0.2.14" tslib: "npm:^2.6.3" + tsx: "npm:^4.20.3" typescript: "npm:^5.5.4" vitest: "npm:^2.1.1" languageName: unknown @@ -9510,6 +9818,16 @@ __metadata: languageName: node linkType: hard +"tinyglobby@npm:^0.2.14": + version: 0.2.14 + resolution: "tinyglobby@npm:0.2.14" + dependencies: + fdir: "npm:^6.4.4" + picomatch: "npm:^4.0.2" + checksum: 10c0/f789ed6c924287a9b7d3612056ed0cda67306cd2c80c249fd280cf1504742b12583a2089b61f4abbd24605f390809017240e250241f09938054c9b363e51c0a6 + languageName: node + linkType: hard + "tinypool@npm:^1.0.0": version: 1.0.1 resolution: "tinypool@npm:1.0.1" @@ -9656,6 +9974,22 @@ __metadata: languageName: node linkType: hard +"tsx@npm:^4.20.3": + version: 4.20.3 + resolution: "tsx@npm:4.20.3" + dependencies: + esbuild: "npm:~0.25.0" + fsevents: "npm:~2.3.3" + get-tsconfig: "npm:^4.7.5" + dependenciesMeta: + fsevents: + optional: true + bin: + tsx: dist/cli.mjs + checksum: 10c0/6ff0d91ed046ec743fac7ed60a07f3c025e5b71a5aaf58f3d2a6b45e4db114c83e59ebbb078c8e079e48d3730b944a02bc0de87695088aef4ec8bbc705dc791b + languageName: node + linkType: hard + "type-check@npm:~0.3.2": version: 0.3.2 resolution: "type-check@npm:0.3.2" @@ -9750,6 +10084,13 @@ __metadata: languageName: node linkType: hard +"undici-types@npm:~6.21.0": + version: 6.21.0 + resolution: "undici-types@npm:6.21.0" + checksum: 10c0/c01ed51829b10aa72fc3ce64b747f8e74ae9b60eafa19a7b46ef624403508a54c526ffab06a14a26b3120d055e1104d7abe7c9017e83ced038ea5cf52f8d5e04 + languageName: node + linkType: hard + "unicode-canonical-property-names-ecmascript@npm:^2.0.0": version: 2.0.0 resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.0"