diff --git a/package.json b/package.json index e8776ce20..6ee68a480 100644 --- a/package.json +++ b/package.json @@ -181,6 +181,11 @@ "import": "./lib/zoom-blur.mjs", "require": "./lib/zoom-blur.js", "types": "./lib/zoom-blur.d.ts" + }, + "./defaults": { + "import": "./lib/defaults.mjs", + "require": "./lib/defaults.js", + "types": "./lib/defaults.d.ts" } }, "main": "lib/index.js", @@ -207,7 +212,8 @@ "copy:demoimages": "copyfiles -f tools/demo/images/* deploy/demo/images", "deploy": "xs deploy", "release": "xs bump,test,deploy,git-push", - "publish-ci": "xs publish" + "publish-ci": "xs publish", + "generate-exports": "node --no-warnings=ExperimentalWarning scripts/generate-exports.mjs" }, "pre-commit": [ "lint", @@ -254,6 +260,7 @@ "docsGoogleAnalytics": "UA-103772589-3", "docsTitle": "PixiJS Filters API Documentation", "docsDescription": "Documentation for PixiJS Filters library", - "docsKeyword": "docs, documentation, pixi, pixijs, filters, webgl, ascii, bloom, convolution, cross-hatch, dotfilter, emboss, pixelate, twist, tiltshift" + "docsKeyword": "docs, documentation, pixi, pixijs, filters, webgl, ascii, bloom, convolution, cross-hatch, dotfilter, emboss, pixelate, twist, tiltshift", + "lint": ["src", "examples", "scripts", "tools/demo/src", "tools/screenshots/*.js"] } } \ No newline at end of file diff --git a/scripts/exports.js b/scripts/exports.js deleted file mode 100644 index 03be3ba3d..000000000 --- a/scripts/exports.js +++ /dev/null @@ -1,36 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -// Define the directory and file paths -const filtersDirPath = path.join(process.cwd(), 'filters'); -const packageJsonPath = path.join(process.cwd(), 'package.json'); - -// Read the package.json file -const packageJson = require(packageJsonPath); - -// Ensure the exports field exists -packageJson.exports = {}; - -packageJson.exports['.'] = { - import: './lib/index.mjs', - require: './lib/index.js', - types: './lib/index.d.js', -}; - -// Read all directories in the filters folder -fs.readdirSync(filtersDirPath, { withFileTypes: true }) - .filter((dirent) => dirent.isDirectory()) - .forEach((dirent) => - { - // Add each directory to the exports field - const dirName = dirent.name; - - packageJson.exports[`./${dirName}`] = { - import: `./lib/${dirName}.mjs`, - require: `./lib/${dirName}.js`, - types: `./lib/${dirName}.d.js`, - }; - }); - -// Write the updated package.json back to disk -fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); diff --git a/scripts/generate-exports.mjs b/scripts/generate-exports.mjs new file mode 100644 index 000000000..1a616dc80 --- /dev/null +++ b/scripts/generate-exports.mjs @@ -0,0 +1,83 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import packageJson from '../package.json' assert { type: 'json' }; + +// Define the directory and file paths +const filtersDirPath = path.resolve('src'); +const packageJsonPath = path.resolve('package.json'); + +// Ensure the exports field exists +packageJson.exports = packageJson.exports ?? {}; + +packageJson.exports['.'] = { + import: './lib/index.mjs', + require: './lib/index.js', + types: './lib/index.d.ts', +}; + +// Read all directories in the filters folder +fs.readdirSync(filtersDirPath, { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .forEach((dirent) => + { + // Add each directory to the exports field + const dirName = dirent.name; + + packageJson.exports[`./${dirName}`] = { + import: `./lib/${dirName}.mjs`, + require: `./lib/${dirName}.js`, + types: `./lib/${dirName}.d.ts`, + }; + }); + +async function fileExists(filePath) +{ + try + { + fs.accessSync(path.resolve(filePath)); + + return true; + } + catch + { + return false; + } +} + +function validateExports(exports) +{ + return Promise.all( + Object.entries(exports).map(async ([key, value]) => + { + const { import: importPath, require: requirePath, types: typesPath } = value; + + if (!importPath || !(await fileExists(importPath))) + { + throw new Error(`The import path "${importPath}" for "${key}" does not exist.`); + } + + if (!requirePath || !(await fileExists(requirePath))) + { + throw new Error(`The require path "${requirePath}" for "${key}" does not exist.`); + } + + if (!typesPath || !(await fileExists(typesPath))) + { + throw new Error(`The types path "${typesPath}" for "${key}" does not exist.`); + } + }) + ); +} + +try +{ + await validateExports(packageJson.exports); + // Write the updated package.json back to disk + fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)); +} +catch (error) +{ + console.error(`ERROR: ${error.message}\n`); + process.exit(1); +} + diff --git a/scripts/rollup-dedupe-vert.js b/scripts/rollup-dedupe-vert.js deleted file mode 100644 index e6ec9b623..000000000 --- a/scripts/rollup-dedupe-vert.js +++ /dev/null @@ -1,61 +0,0 @@ -import fs from 'fs'; -import MagicString from 'magic-string'; -import path from 'path'; - -/** - * This plugin is a filesize optimization for the pixi-filters bundle - * it removes all the successive occurances of the default vertex fragment - * and reassigns the name of the vertex variable - * @function dedupeDefaultVert - * @private - */ -function dedupeDefaultVert() -{ - const defaultVert = path.resolve('tools/fragments/default.vert'); - const fragment = fs.readFileSync(defaultVert, 'utf8') - .replace(/\n/g, '\\\\n') - .replace(/([()*=.])/g, '\\$1'); - - const pattern = new RegExp(`(var ([^=\\s]+)\\s?=\\s?)"${fragment}"`, 'g'); - - return { - name: 'dedupeDefaultVert', - renderChunk(code) - { - const matches = []; - let match; - - while ((match = pattern.exec(code)) !== null) - { - matches.push(match); - } - - if (matches.length <= 1) - { - return null; - } - - const str = new MagicString(code); - const key = matches[0][2]; - - for (let i = 1; i < matches.length; i++) - { - const match = matches[i]; - const start = code.indexOf(match[0]); - - str.overwrite( - start, - start + match[0].length, - match[1] + key - ); - } - - return { - code: str.toString(), - map: str.generateMap({ hires: true }), - }; - }, - }; -} - -export default dedupeDefaultVert; diff --git a/src/adjustment/index.ts b/src/adjustment/index.ts index 587ef500a..1f6c0ff56 100644 --- a/src/adjustment/index.ts +++ b/src/adjustment/index.ts @@ -1 +1 @@ -export * from './AdjustmentFilter.js'; +export * from './AdjustmentFilter'; diff --git a/src/color-map/index.ts b/src/color-map/index.ts index 401d2face..3147e74cd 100644 --- a/src/color-map/index.ts +++ b/src/color-map/index.ts @@ -1 +1 @@ -export * from './ColorMapFilter.js'; +export * from './ColorMapFilter'; diff --git a/src/crt/index.ts b/src/crt/index.ts index b68874331..bd63669d9 100644 --- a/src/crt/index.ts +++ b/src/crt/index.ts @@ -1 +1 @@ -export * from './CRTFilter.js'; +export * from './CRTFilter'; diff --git a/src/glitch/index.ts b/src/glitch/index.ts index 61f101d45..39383cfef 100644 --- a/src/glitch/index.ts +++ b/src/glitch/index.ts @@ -1 +1 @@ -export * from './GlitchFilter.js'; +export * from './GlitchFilter'; diff --git a/src/kawase-blur/index.ts b/src/kawase-blur/index.ts index 912ec217e..86c36f43f 100644 --- a/src/kawase-blur/index.ts +++ b/src/kawase-blur/index.ts @@ -1 +1 @@ -export * from './KawaseBlurFilter.js'; +export * from './KawaseBlurFilter'; diff --git a/src/motion-blur/index.ts b/src/motion-blur/index.ts index f22c1bb7d..ff2fcce73 100644 --- a/src/motion-blur/index.ts +++ b/src/motion-blur/index.ts @@ -1 +1 @@ -export * from './MotionBlurFilter.js'; +export * from './MotionBlurFilter'; diff --git a/src/multi-color-replace/index.ts b/src/multi-color-replace/index.ts index 0cc6c4649..00be09651 100644 --- a/src/multi-color-replace/index.ts +++ b/src/multi-color-replace/index.ts @@ -1 +1 @@ -export * from './MultiColorReplaceFilter.js'; +export * from './MultiColorReplaceFilter'; diff --git a/src/old-film/index.ts b/src/old-film/index.ts index f198d149b..c18e13a73 100644 --- a/src/old-film/index.ts +++ b/src/old-film/index.ts @@ -1 +1 @@ -export * from './OldFilmFilter.js'; +export * from './OldFilmFilter'; diff --git a/src/radial-blur/index.ts b/src/radial-blur/index.ts index 38cd38baa..0ebd5cda2 100644 --- a/src/radial-blur/index.ts +++ b/src/radial-blur/index.ts @@ -1 +1 @@ -export * from './RadialBlurFilter.js'; +export * from './RadialBlurFilter'; diff --git a/src/reflection/index.ts b/src/reflection/index.ts index bed2c9aeb..9a3f3b39e 100644 --- a/src/reflection/index.ts +++ b/src/reflection/index.ts @@ -1 +1 @@ -export * from './ReflectionFilter.js'; +export * from './ReflectionFilter'; diff --git a/src/zoom-blur/index.ts b/src/zoom-blur/index.ts index c78f0c847..dae4f4033 100644 --- a/src/zoom-blur/index.ts +++ b/src/zoom-blur/index.ts @@ -1 +1 @@ -export * from './ZoomBlurFilter.js'; +export * from './ZoomBlurFilter'; diff --git a/tools/demo/src/filters/.eslintrc b/tools/demo/src/filters/.eslintrc new file mode 100644 index 000000000..1d7afcc0d --- /dev/null +++ b/tools/demo/src/filters/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "func-names": "off" + } +} \ No newline at end of file