From 4a2082b4db285105a317354952f99f24f982b877 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 18 Mar 2025 09:04:59 -0400 Subject: [PATCH] Convert docs and types scripts to .mjs to fix node errors on some platforms --- docs/parameterData.json | 325 ++---------------- package.json | 4 +- src/type/p5.Font.js | 3 + test/unit/types/generate-types.js | 32 +- utils/{convert.js => convert.mjs} | 2 +- .../{generate-types.js => generate-types.mjs} | 2 +- utils/{helper.js => helper.mjs} | 0 utils/{patch.js => patch.mjs} | 0 8 files changed, 57 insertions(+), 311 deletions(-) rename utils/{convert.js => convert.mjs} (99%) rename utils/{generate-types.js => generate-types.mjs} (99%) rename utils/{helper.js => helper.mjs} (100%) rename utils/{patch.js => patch.mjs} (100%) diff --git a/docs/parameterData.json b/docs/parameterData.json index 5e0008210b..b55706f351 100644 --- a/docs/parameterData.json +++ b/docs/parameterData.json @@ -402,11 +402,6 @@ [] ] }, - "preload": { - "overloads": [ - [] - ] - }, "createCanvas": { "overloads": [ [ @@ -629,28 +624,6 @@ ] ] }, - "createStringDict": { - "overloads": [ - [ - "String", - "String" - ], - [ - "Object" - ] - ] - }, - "createNumberDict": { - "overloads": [ - [ - "Number", - "Number" - ], - [ - "Object" - ] - ] - }, "select": { "overloads": [ [ @@ -2097,86 +2070,6 @@ [] ] }, - "append": { - "overloads": [ - [ - "Array", - "Any" - ] - ] - }, - "arrayCopy": { - "overloads": [ - [ - "Array", - "Integer", - "Array", - "Integer", - "Integer" - ], - [ - "Array", - "Array", - "Integer?" - ] - ] - }, - "concat": { - "overloads": [ - [ - "Array", - "Array" - ] - ] - }, - "reverse": { - "overloads": [ - [ - "Array" - ] - ] - }, - "shorten": { - "overloads": [ - [ - "Array" - ] - ] - }, - "shuffle": { - "overloads": [ - [ - "Array", - "Boolean?" - ] - ] - }, - "sort": { - "overloads": [ - [ - "Array", - "Integer?" - ] - ] - }, - "splice": { - "overloads": [ - [ - "Array", - "Any", - "Integer" - ] - ] - }, - "subset": { - "overloads": [ - [ - "Array", - "Integer", - "Integer?" - ] - ] - }, "float": { "overloads": [ [ @@ -2266,28 +2159,39 @@ ] ] }, - "join": { + "day": { "overloads": [ - [ - "Array", - "String" - ] + [] ] }, - "match": { + "hour": { "overloads": [ - [ - "String", - "String" - ] + [] ] }, - "matchAll": { + "minute": { "overloads": [ - [ - "String", - "String" - ] + [] + ] + }, + "millis": { + "overloads": [ + [] + ] + }, + "month": { + "overloads": [ + [] + ] + }, + "second": { + "overloads": [ + [] + ] + }, + "year": { + "overloads": [ + [] ] }, "nf": { @@ -2344,14 +2248,6 @@ ] ] }, - "split": { - "overloads": [ - [ - "String", - "String" - ] - ] - }, "splitTokens": { "overloads": [ [ @@ -2360,51 +2256,14 @@ ] ] }, - "trim": { + "shuffle": { "overloads": [ [ - "String" - ], - [ - "String[]" + "Array", + "Boolean?" ] ] }, - "day": { - "overloads": [ - [] - ] - }, - "hour": { - "overloads": [ - [] - ] - }, - "minute": { - "overloads": [ - [] - ] - }, - "millis": { - "overloads": [ - [] - ] - }, - "month": { - "overloads": [ - [] - ] - }, - "second": { - "overloads": [ - [] - ] - }, - "year": { - "overloads": [ - [] - ] - }, "strokeMode": { "overloads": [ [ @@ -3315,127 +3174,6 @@ ] } }, - "p5.TypedDict": { - "size": { - "overloads": [ - [] - ] - }, - "hasKey": { - "overloads": [ - [ - "Number|String" - ] - ] - }, - "get": { - "overloads": [ - [ - "Number|String" - ] - ] - }, - "set": { - "overloads": [ - [ - "Number|String", - "Number|String" - ] - ] - }, - "create": { - "overloads": [ - [ - "Number|String", - "Number|String" - ], - [ - "Object" - ] - ] - }, - "clear": { - "overloads": [ - [] - ] - }, - "remove": { - "overloads": [ - [ - "Number|String" - ] - ] - }, - "print": { - "overloads": [ - [] - ] - }, - "saveTable": { - "overloads": [ - [] - ] - }, - "saveJSON": { - "overloads": [ - [] - ] - } - }, - "p5.NumberDict": { - "add": { - "overloads": [ - [ - "Number", - "Number" - ] - ] - }, - "sub": { - "overloads": [ - [ - "Number", - "Number" - ] - ] - }, - "mult": { - "overloads": [ - [ - "Number", - "Number" - ] - ] - }, - "div": { - "overloads": [ - [ - "Number", - "Number" - ] - ] - }, - "minValue": { - "overloads": [ - [] - ] - }, - "maxValue": { - "overloads": [ - [] - ] - }, - "minKey": { - "overloads": [ - [] - ] - }, - "maxKey": { - "overloads": [ - [] - ] - } - }, "p5.Graphics": { "reset": { "overloads": [ @@ -4706,6 +4444,11 @@ } }, "p5.Font": { + "textToModel": { + "overloads": [ + [] + ] + }, "hasGlyphData": { "overloads": [ [] diff --git a/package.json b/package.json index 1c72510187..3eb64225fc 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "build": "rollup -c", "dev": "vite preview/", "dev:global": "concurrently -n build,server \"rollup -c -w\" \"npx vite preview/global/\"", - "docs": "documentation build ./src/**/*.js ./src/**/**/*.js -o ./docs/data.json && node ./utils/convert.js", + "docs": "documentation build ./src/**/*.js ./src/**/**/*.js -o ./docs/data.json && node ./utils/convert.mjs", "bench": "vitest bench", "bench:report": "vitest bench --reporter=verbose", "test": "vitest", "lint": "eslint .", "lint:fix": "eslint --fix .", - "generate-types": "npm run docs && node utils/generate-types && node utils/patch" + "generate-types": "npm run docs && node utils/generate-types.mjs && node utils/patch.mjs" }, "lint-staged": { "Gruntfile.js": "eslint", diff --git a/src/type/p5.Font.js b/src/type/p5.Font.js index fcebf28410..52c6755f8b 100644 --- a/src/type/p5.Font.js +++ b/src/type/p5.Font.js @@ -128,6 +128,9 @@ class Font { return cmdContours.map((commands) => pathToPoints(commands, options, this)); } + /** + * Test + */ textToModel(str, x, y, width, height, options) { ({ width, height, options } = this._parseArgs(width, height, options)); const extrude = options?.extrude || 0; diff --git a/test/unit/types/generate-types.js b/test/unit/types/generate-types.js index 5688b38d15..88d19b5e1a 100644 --- a/test/unit/types/generate-types.js +++ b/test/unit/types/generate-types.js @@ -1,5 +1,5 @@ import { suite, test, expect } from 'vitest'; -import { +import { normalizeClassName, generateTypeFromTag, generateParamDeclaration, @@ -7,7 +7,7 @@ import { generateClassDeclaration, generateMethodDeclarations, generateTypeDefinitions -} from '../../../utils/helper.js'; +} from '../../../utils/helper.mjs'; // Move absFuncDoc to the top level const absFuncDoc = { @@ -198,14 +198,14 @@ suite('normalizeClassName', () => { suite('generateTypeFromTag', () => { test('should handle primitive types', () => { - expect(generateTypeFromTag({ - type: { type: 'NameExpression', name: 'Number' } + expect(generateTypeFromTag({ + type: { type: 'NameExpression', name: 'Number' } })).toBe('number'); - expect(generateTypeFromTag({ - type: { type: 'NameExpression', name: 'String' } + expect(generateTypeFromTag({ + type: { type: 'NameExpression', name: 'String' } })).toBe('string'); - expect(generateTypeFromTag({ - type: { type: 'NameExpression', name: 'Boolean' } + expect(generateTypeFromTag({ + type: { type: 'NameExpression', name: 'Boolean' } })).toBe('boolean'); }); @@ -243,7 +243,7 @@ suite('generateParamDeclaration', () => { test('should handle optional parameters', () => { expect(generateParamDeclaration({ name: 'y', - type: { + type: { type: 'OptionalType', expression: { type: 'NameExpression', name: 'String' } } @@ -274,9 +274,9 @@ suite('generateClassDeclaration', () => { { name: 'renderer', type: { type: 'NameExpression', name: 'p5.RendererGL' } }, { name: 'vertSrc', type: { type: 'NameExpression', name: 'string' } }, { name: 'fragSrc', type: { type: 'NameExpression', name: 'string' } }, - { + { name: 'options', - type: { + type: { type: 'OptionalType', expression: { type: 'NameExpression', name: 'object' } } @@ -303,9 +303,9 @@ suite('generateMethodDeclarations', () => { name: 'copyToContext', kind: 'function', description: '', - params: [{ + params: [{ name: 'context', - type: { + type: { type: 'UnionType', elements: [ { type: 'NameExpression', name: 'p5' }, @@ -330,7 +330,7 @@ suite('generateMethodDeclarations', () => { suite('generateTypeDefinitions', () => { test('should generate type definitions from minimal data', () => { const result = generateTypeDefinitions([absFuncDoc]); - + const expectedContent = '// This file is auto-generated from JSDoc documentation\n\n' + 'import p5 from \'p5\';\n\n' + 'declare module \'p5\' {\n' + @@ -369,9 +369,9 @@ suite('generateTypeDefinitions', () => { '}\n\n'; const filePath = 'C:\\Users\\diyas\\Documents\\p5.js\\src\\math\\calculation.js'; - + // Helper function to normalize whitespace and newlines - const normalizeString = (str) => + const normalizeString = (str) => str.replace(/\s+/g, ' ') .replace(/\n\s*/g, '\n') .trim(); diff --git a/utils/convert.js b/utils/convert.mjs similarity index 99% rename from utils/convert.js rename to utils/convert.mjs index 4266926015..da7965761f 100644 --- a/utils/convert.js +++ b/utils/convert.mjs @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; -import { getAllEntries } from './helper.js'; +import { getAllEntries } from './helper.mjs'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/utils/generate-types.js b/utils/generate-types.mjs similarity index 99% rename from utils/generate-types.js rename to utils/generate-types.mjs index 991e1c0337..6ea600a2c6 100644 --- a/utils/generate-types.js +++ b/utils/generate-types.mjs @@ -3,7 +3,7 @@ import path from 'path'; import { fileURLToPath } from 'url'; import { generateTypeDefinitions -} from "./helper.js"; +} from "./helper.mjs"; // Fix for __dirname equivalent in ES modules const __filename = fileURLToPath(import.meta.url); diff --git a/utils/helper.js b/utils/helper.mjs similarity index 100% rename from utils/helper.js rename to utils/helper.mjs diff --git a/utils/patch.js b/utils/patch.mjs similarity index 100% rename from utils/patch.js rename to utils/patch.mjs