phetsims / chipper

Tools for developing and building PhET interactive simulations.
MIT License
11 stars 14 forks source link

Run Grunt tasks in separate processes #1459

Closed samreid closed 4 hours ago

samreid commented 6 days ago

From an idea in https://github.com/phetsims/chipper/issues/1437, we could use grunt as a thin wrapper that spawns a new process in a runtime under our control. This will help us modularize and isolate our dependence on grunt, and allow us flexibility to use alternate runtimes such as tsx and TypeScript.

samreid commented 5 days ago

Patch to go into npx tsx:

```diff Subject: [PATCH] Revert multi-modal transpilation output, see https://github.com/phetsims/chipper/issues/1459 --- Index: js/grunt/typescript-test.ts =================================================================== diff --git a/js/grunt/typescript-test.ts b/js/grunt/typescript-test.ts deleted file mode 100644 --- a/js/grunt/typescript-test.ts (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) +++ /dev/null (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) @@ -1,18 +0,0 @@ -// Copyright 2024, University of Colorado Boulder - -/** - * TODO: delete as part of https://github.com/phetsims/chipper/issues/1437 - * @author Michael Kauzmann (PhET Interactive Simulations) - * @author Sam Reid (PhET Interactive Simulations) - */ - -module.exports = function typescriptTest() { - - const myTestNumber = 9; - - function myPrintFunc( x: number ): void { - console.log( x ); - } - - myPrintFunc( myTestNumber ); -}; \ No newline at end of file Index: js/grunt/.eslintrc.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/.eslintrc.js b/js/grunt/.eslintrc.js --- a/js/grunt/.eslintrc.js (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) +++ b/js/grunt/.eslintrc.js (date 1726152280519) @@ -4,5 +4,31 @@ module.exports = { // Use all of the default rules from eslint file for node code. - extends: '../../../chipper/eslint/chipper_eslintrc.js' + extends: process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/eslint/chipper_eslintrc.js', + + parserOptions: { + sourceType: 'module' + }, + + overrides: [ { + files: [ '**/*.ts' ], + + parserOptions: { + + // Provide a tsconfig so that we can use rules that require type information. + // NOTE: Providing this slows down eslint substantially, see https://github.com/phetsims/chipper/issues/1114#issuecomment-1065927717 + + // IntelliJ runs this from chipper/js/grunt so the path is different than when running from chipper/, so we must normalize + // to support both IDE and command line + // for debugging here, you can put variables into the project then navigate to a file using this (like a *.ts file) + // and see the output in the bad path, or you can write to the file system. + project: [ process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/tsconfig/all/tsconfig.json' ] + }, + + // disable rules @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires + rules: { + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-var-requires': 'off' + } + } ] }; \ No newline at end of file Index: tsconfig/all/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig/all/tsconfig.json b/tsconfig/all/tsconfig.json --- a/tsconfig/all/tsconfig.json (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) +++ b/tsconfig/all/tsconfig.json (date 1726151891950) @@ -32,7 +32,7 @@ "../../../center-and-variability/images/**/*", "../../../chipper/phet-types.d.ts", "../../../chipper/phet-types-module.d.ts", - "../../../chipper/js/grunt/typescript-test.ts", + "../../../chipper/js/grunt/**/*", "../../../circuit-construction-kit-ac/js/**/*", "../../../circuit-construction-kit-ac-virtual-lab/js/**/*", "../../../circuit-construction-kit-common/js/**/*", Index: js/grunt/tasks/update.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/update.js b/js/grunt/tasks/update.js --- a/js/grunt/tasks/update.js (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) +++ b/js/grunt/tasks/update.js (date 1726152358767) @@ -25,6 +25,7 @@ // modulify is graceful if there are no files that need modulifying. // TODO: This used to be grunt.task.run, is plain require correct here? https://github.com/phetsims/chipper/issues/1459 + // TODO: Does this process the command line args correctly? see https://github.com/phetsims/chipper/issues/1459 require( './modulify' ); // update README.md only for simulations Index: js/grunt/tasks/build.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/build.js b/js/grunt/tasks/build.ts rename from js/grunt/tasks/build.js rename to js/grunt/tasks/build.ts --- a/js/grunt/tasks/build.js (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) +++ b/js/grunt/tasks/build.ts (date 1726152524910) @@ -16,6 +16,8 @@ const grunt = require( 'grunt' ); const getRepo = require( './getRepo' ); + +// @ts-expect-error - overlaps with global assert in phet-types.d.ts TODO https://github.com/phetsims/chipper/issues/1459 const assert = require( 'assert' ); const Transpiler = require( '../../common/Transpiler' ); const getBrands = require( './getBrands' ); @@ -29,12 +31,12 @@ const transpiler = new Transpiler( { silent: true } ); -( async () => { +( async () => { /* eslint-disable-line @typescript-eslint/no-floating-promises */ // TODO: https://github.com/phetsims/chipper/issues/1459 ??? await phetTimingLog.startAsync( 'grunt-build', async () => { // Parse minification keys const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS ); - const minifyOptions = {}; + const minifyOptions: Record = {}; minifyKeys.forEach( minifyKey => { const option = grunt.option( `minify.${minifyKey}` ); if ( option === true || option === false ) { @@ -101,7 +103,7 @@ else { const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` ); - assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); + assert && assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); grunt.log.writeln( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` ); // Other options Index: js/grunt/Gruntfile.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js --- a/js/grunt/Gruntfile.js (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) +++ b/js/grunt/Gruntfile.js (date 1726151489505) @@ -41,13 +41,22 @@ // TODO switch to npx tsx, see https://github.com/phetsims/chipper/issues/1459 via npx ../chipper/node_modules/tsx // TODO: test on windows, see https://github.com/phetsims/chipper/issues/1459 - const command = 'node'; + const command = 'npx'; return () => { const done = grunt.task.current.async(); try { - const child = spawn( command, [ `../chipper/js/grunt/tasks/${taskFilename}`, ...process.argv.slice( 2 ) ], { stdio: [ 'inherit', 'pipe', 'pipe' ] } ); + const child = spawn( command, [ + + // so we don't have to install tsx globally or in every sim repo + '../chipper/node_modules/tsx', + + `../chipper/js/grunt/tasks/${taskFilename}`, + ...process.argv.slice( 2 ) + ], { + stdio: [ 'inherit', 'pipe', 'pipe' ] + } ); child.stdout.on( 'data', data => process.stdout.write( data.toString() ) ); child.stderr.on( 'data', data => process.stderr.write( data.toString() ) ); Index: package.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/package.json b/package.json --- a/package.json (revision 00b31dedbb416ba07f5291c27f63c904ccf929b2) +++ b/package.json (date 1726146952884) @@ -58,6 +58,7 @@ "taffydb": "~2.7.3", "terser": "~4.6.4", "ts-morph": "^21.0.1", + "tsx": "^4.19.1", "typescript": "~5.5.4", "webpack": "~5.76.3", "webpack-cli": "~5.0.0",
samreid commented 5 days ago

Current jab script:

```bash function jab() { # The base directory where all your task scripts are stored base_dir="../chipper/js/grunt/tasks" # Check if the first argument is missing or starts with a hyphen (indicating options) if [[ -z "$1" || "$1" =~ ^- ]]; then task="build" else task="$1" shift fi # Construct the paths to the script files (both .ts and .js) ts_script_file="$base_dir/${task}.ts" js_script_file="$base_dir/${task}.js" # Check if the .ts script file exists first if [[ -f "$ts_script_file" ]]; then # Execute the command with the remaining arguments using the TypeScript file ../chipper/node_modules/.bin/tsx "$ts_script_file" "$@" # If the .ts file doesn't exist, check for the .js file elif [[ -f "$js_script_file" ]]; then # Execute the command with the remaining arguments using the JavaScript file ../chipper/node_modules/.bin/tsx "$js_script_file" "$@" else # If neither file is found, display an error message echo "Unknown command or script file not found: $task" fi }
samreid commented 5 days ago

Update patch:

```diff Subject: [PATCH] Revert multi-modal transpilation output, see https://github.com/phetsims/chipper/issues/1459 --- Index: js/grunt/typescript-test.ts =================================================================== diff --git a/js/grunt/typescript-test.ts b/js/grunt/typescript-test.ts deleted file mode 100644 --- a/js/grunt/typescript-test.ts (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ /dev/null (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) @@ -1,18 +0,0 @@ -// Copyright 2024, University of Colorado Boulder - -/** - * TODO: delete as part of https://github.com/phetsims/chipper/issues/1437 - * @author Michael Kauzmann (PhET Interactive Simulations) - * @author Sam Reid (PhET Interactive Simulations) - */ - -module.exports = function typescriptTest() { - - const myTestNumber = 9; - - function myPrintFunc( x: number ): void { - console.log( x ); - } - - myPrintFunc( myTestNumber ); -}; \ No newline at end of file Index: js/grunt/.eslintrc.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/.eslintrc.js b/js/grunt/.eslintrc.js --- a/js/grunt/.eslintrc.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/.eslintrc.js (date 1726170610759) @@ -4,5 +4,31 @@ module.exports = { // Use all of the default rules from eslint file for node code. - extends: '../../../chipper/eslint/chipper_eslintrc.js' + extends: process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/eslint/chipper_eslintrc.js', + + parserOptions: { + sourceType: 'module' + }, + + overrides: [ { + files: [ '**/*.ts' ], + + parserOptions: { + + // Provide a tsconfig so that we can use rules that require type information. + // NOTE: Providing this slows down eslint substantially, see https://github.com/phetsims/chipper/issues/1114#issuecomment-1065927717 + + // IntelliJ runs this from chipper/js/grunt so the path is different than when running from chipper/, so we must normalize + // to support both IDE and command line + // for debugging here, you can put variables into the project then navigate to a file using this (like a *.ts file) + // and see the output in the bad path, or you can write to the file system. + project: [ process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/tsconfig/all/tsconfig.json' ] + }, + + // disable rules @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires + rules: { + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-var-requires': 'off' + } + } ] }; \ No newline at end of file Index: tsconfig/all/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig/all/tsconfig.json b/tsconfig/all/tsconfig.json --- a/tsconfig/all/tsconfig.json (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/tsconfig/all/tsconfig.json (date 1726170610786) @@ -32,7 +32,7 @@ "../../../center-and-variability/images/**/*", "../../../chipper/phet-types.d.ts", "../../../chipper/phet-types-module.d.ts", - "../../../chipper/js/grunt/typescript-test.ts", + "../../../chipper/js/grunt/**/*", "../../../circuit-construction-kit-ac/js/**/*", "../../../circuit-construction-kit-ac-virtual-lab/js/**/*", "../../../circuit-construction-kit-common/js/**/*", Index: js/grunt/tasks/update.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/update.js b/js/grunt/tasks/update.js --- a/js/grunt/tasks/update.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/tasks/update.js (date 1726170610751) @@ -25,6 +25,7 @@ // modulify is graceful if there are no files that need modulifying. // TODO: This used to be grunt.task.run, is plain require correct here? https://github.com/phetsims/chipper/issues/1459 + // TODO: Does this process the command line args correctly? see https://github.com/phetsims/chipper/issues/1459 require( './modulify' ); // update README.md only for simulations Index: tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig.json b/tsconfig.json --- a/tsconfig.json (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/tsconfig.json (date 1726171296778) @@ -5,5 +5,8 @@ "images/**/*", "mipmaps/**/*", "sounds/**/*" - ] + ], + "compilerOptions": { + "allowSyntheticDefaultImports": true + } } \ No newline at end of file Index: js/grunt/Gruntfile.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js --- a/js/grunt/Gruntfile.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/Gruntfile.js (date 1726171111960) @@ -41,13 +41,22 @@ // TODO switch to npx tsx, see https://github.com/phetsims/chipper/issues/1459 via npx ../chipper/node_modules/tsx // TODO: test on windows, see https://github.com/phetsims/chipper/issues/1459 - const command = 'node'; + const command = '../chipper/node_modules/.bin/tsx'; return () => { const done = grunt.task.current.async(); try { - const child = spawn( command, [ `../chipper/js/grunt/tasks/${taskFilename}`, ...process.argv.slice( 2 ) ], { stdio: [ 'inherit', 'pipe', 'pipe' ] } ); + const child = spawn( command, [ + + // so we don't have to install tsx globally or in every sim repo + // '../chipper/node_modules/tsx', + + `../chipper/js/grunt/tasks/${taskFilename}`, + ...process.argv.slice( 2 ) + ], { + stdio: [ 'inherit', 'pipe', 'pipe' ] + } ); child.stdout.on( 'data', data => process.stdout.write( data.toString() ) ); child.stderr.on( 'data', data => process.stderr.write( data.toString() ) ); Index: package.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/package.json b/package.json --- a/package.json (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/package.json (date 1726170610796) @@ -58,6 +58,7 @@ "taffydb": "~2.7.3", "terser": "~4.6.4", "ts-morph": "^21.0.1", + "tsx": "^4.19.1", "typescript": "~5.5.4", "webpack": "~5.76.3", "webpack-cli": "~5.0.0", Index: js/grunt/tasks/parseGruntOptions.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/parseGruntOptions.js b/js/grunt/tasks/parseGruntOptions.js --- a/js/grunt/tasks/parseGruntOptions.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/tasks/parseGruntOptions.js (date 1726171440639) @@ -6,7 +6,7 @@ // TODO: Replace with nopt 4.0.1 to guarantee compatibility with grunt. See usage site: https://github.com/phetsims/chipper/issues/1459 // /Users/samreid/phet/root/chipper/node_modules/grunt-cli/bin/grunt -module.exports = function( grunt ) { +const myFunc = function( grunt ) { function parseArgs( argv ) { const args = {}; argv.forEach( ( arg, index ) => { @@ -33,4 +33,8 @@ const parsedArgs = parseArgs( process.argv.slice( 2 ) ); return parsedArgs; -}; \ No newline at end of file +}; + +myFunc.tester = 'hello'; + +module.exports = myFunc; \ No newline at end of file Index: js/grunt/tasks/build.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/build.js b/js/grunt/tasks/build.ts rename from js/grunt/tasks/build.js rename to js/grunt/tasks/build.ts --- a/js/grunt/tasks/build.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/tasks/build.ts (date 1726171440649) @@ -16,25 +16,36 @@ const grunt = require( 'grunt' ); const getRepo = require( './getRepo' ); + +// @ts-expect-error - overlaps with global assert in phet-types.d.ts TODO https://github.com/phetsims/chipper/issues/1459 const assert = require( 'assert' ); const Transpiler = require( '../../common/Transpiler' ); const getBrands = require( './getBrands' ); -const parseGruntOptions = require( './parseGruntOptions' ); +import parseGruntOptions from './parseGruntOptions'; + +console.log( parseGruntOptions ); + +parseGruntOptions.tester; +parseGruntOptions.minify; +// parseGruntOptions.hello; +// parseGruntOptions(); + const repo = getRepo(); + // Initialize Grunt options with parsed arguments // Call this before getBrands grunt.option.init( parseGruntOptions() ); const transpiler = new Transpiler( { silent: true } ); -( async () => { +( async () => { /* eslint-disable-line @typescript-eslint/no-floating-promises */ // TODO: https://github.com/phetsims/chipper/issues/1459 ??? await phetTimingLog.startAsync( 'grunt-build', async () => { // Parse minification keys const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS ); - const minifyOptions = {}; + const minifyOptions: Record = {}; minifyKeys.forEach( minifyKey => { const option = grunt.option( `minify.${minifyKey}` ); if ( option === true || option === false ) { @@ -101,7 +112,7 @@ else { const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` ); - assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); + assert && assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); grunt.log.writeln( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` ); // Other options
samreid commented 5 days ago

This one is a little cleaner:

```diff Subject: [PATCH] Revert multi-modal transpilation output, see https://github.com/phetsims/chipper/issues/1459 --- Index: js/grunt/typescript-test.ts =================================================================== diff --git a/js/grunt/typescript-test.ts b/js/grunt/typescript-test.ts deleted file mode 100644 --- a/js/grunt/typescript-test.ts (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ /dev/null (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) @@ -1,18 +0,0 @@ -// Copyright 2024, University of Colorado Boulder - -/** - * TODO: delete as part of https://github.com/phetsims/chipper/issues/1437 - * @author Michael Kauzmann (PhET Interactive Simulations) - * @author Sam Reid (PhET Interactive Simulations) - */ - -module.exports = function typescriptTest() { - - const myTestNumber = 9; - - function myPrintFunc( x: number ): void { - console.log( x ); - } - - myPrintFunc( myTestNumber ); -}; \ No newline at end of file Index: js/grunt/.eslintrc.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/.eslintrc.js b/js/grunt/.eslintrc.js --- a/js/grunt/.eslintrc.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/.eslintrc.js (date 1726170610759) @@ -4,5 +4,31 @@ module.exports = { // Use all of the default rules from eslint file for node code. - extends: '../../../chipper/eslint/chipper_eslintrc.js' + extends: process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/eslint/chipper_eslintrc.js', + + parserOptions: { + sourceType: 'module' + }, + + overrides: [ { + files: [ '**/*.ts' ], + + parserOptions: { + + // Provide a tsconfig so that we can use rules that require type information. + // NOTE: Providing this slows down eslint substantially, see https://github.com/phetsims/chipper/issues/1114#issuecomment-1065927717 + + // IntelliJ runs this from chipper/js/grunt so the path is different than when running from chipper/, so we must normalize + // to support both IDE and command line + // for debugging here, you can put variables into the project then navigate to a file using this (like a *.ts file) + // and see the output in the bad path, or you can write to the file system. + project: [ process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/tsconfig/all/tsconfig.json' ] + }, + + // disable rules @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires + rules: { + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-var-requires': 'off' + } + } ] }; \ No newline at end of file Index: tsconfig/all/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig/all/tsconfig.json b/tsconfig/all/tsconfig.json --- a/tsconfig/all/tsconfig.json (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/tsconfig/all/tsconfig.json (date 1726170610786) @@ -32,7 +32,7 @@ "../../../center-and-variability/images/**/*", "../../../chipper/phet-types.d.ts", "../../../chipper/phet-types-module.d.ts", - "../../../chipper/js/grunt/typescript-test.ts", + "../../../chipper/js/grunt/**/*", "../../../circuit-construction-kit-ac/js/**/*", "../../../circuit-construction-kit-ac-virtual-lab/js/**/*", "../../../circuit-construction-kit-common/js/**/*", Index: js/grunt/tasks/update.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/update.js b/js/grunt/tasks/update.js --- a/js/grunt/tasks/update.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/tasks/update.js (date 1726170610751) @@ -25,6 +25,7 @@ // modulify is graceful if there are no files that need modulifying. // TODO: This used to be grunt.task.run, is plain require correct here? https://github.com/phetsims/chipper/issues/1459 + // TODO: Does this process the command line args correctly? see https://github.com/phetsims/chipper/issues/1459 require( './modulify' ); // update README.md only for simulations Index: tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig.json b/tsconfig.json --- a/tsconfig.json (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/tsconfig.json (date 1726171296778) @@ -5,5 +5,8 @@ "images/**/*", "mipmaps/**/*", "sounds/**/*" - ] + ], + "compilerOptions": { + "allowSyntheticDefaultImports": true + } } \ No newline at end of file Index: js/grunt/Gruntfile.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js --- a/js/grunt/Gruntfile.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/Gruntfile.js (date 1726191216346) @@ -41,13 +41,20 @@ // TODO switch to npx tsx, see https://github.com/phetsims/chipper/issues/1459 via npx ../chipper/node_modules/tsx // TODO: test on windows, see https://github.com/phetsims/chipper/issues/1459 - const command = 'node'; + // TODO: // so we don't have to install tsx globally or in every sim repo + const command = '../chipper/node_modules/.bin/tsx'; return () => { const done = grunt.task.current.async(); try { - const child = spawn( command, [ `../chipper/js/grunt/tasks/${taskFilename}`, ...process.argv.slice( 2 ) ], { stdio: [ 'inherit', 'pipe', 'pipe' ] } ); + const child = spawn( command, [ + + `../chipper/js/grunt/tasks/${taskFilename}`, + ...process.argv.slice( 2 ) + ], { + stdio: [ 'inherit', 'pipe', 'pipe' ] + } ); child.stdout.on( 'data', data => process.stdout.write( data.toString() ) ); child.stderr.on( 'data', data => process.stderr.write( data.toString() ) ); Index: package.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/package.json b/package.json --- a/package.json (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/package.json (date 1726170610796) @@ -58,6 +58,7 @@ "taffydb": "~2.7.3", "terser": "~4.6.4", "ts-morph": "^21.0.1", + "tsx": "^4.19.1", "typescript": "~5.5.4", "webpack": "~5.76.3", "webpack-cli": "~5.0.0", Index: js/grunt/tasks/build.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/build.js b/js/grunt/tasks/build.ts rename from js/grunt/tasks/build.js rename to js/grunt/tasks/build.ts --- a/js/grunt/tasks/build.js (revision 8c920866f087ccc42cd1916f2eadf61e699cae95) +++ b/js/grunt/tasks/build.ts (date 1726191216358) @@ -16,10 +16,12 @@ const grunt = require( 'grunt' ); const getRepo = require( './getRepo' ); + +// @ts-expect-error - overlaps with global assert in phet-types.d.ts TODO https://github.com/phetsims/chipper/issues/1459 const assert = require( 'assert' ); const Transpiler = require( '../../common/Transpiler' ); const getBrands = require( './getBrands' ); -const parseGruntOptions = require( './parseGruntOptions' ); +import parseGruntOptions from './parseGruntOptions'; const repo = getRepo(); @@ -29,12 +31,12 @@ const transpiler = new Transpiler( { silent: true } ); -( async () => { +( async () => { /* eslint-disable-line @typescript-eslint/no-floating-promises */ // TODO: https://github.com/phetsims/chipper/issues/1459 ??? await phetTimingLog.startAsync( 'grunt-build', async () => { // Parse minification keys const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS ); - const minifyOptions = {}; + const minifyOptions: Record = {}; minifyKeys.forEach( minifyKey => { const option = grunt.option( `minify.${minifyKey}` ); if ( option === true || option === false ) { @@ -101,7 +103,7 @@ else { const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` ); - assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); + assert && assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); grunt.log.writeln( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` ); // Other options
samreid commented 5 days ago

Some commits in https://github.com/phetsims/chipper/issues/1437 with typescript in chipper/js/grunt/ that we may want to move over here.

samreid commented 4 days ago

In order to accomplish:

Preserve history of tasks over --follow via copying Gruntfile

we will work in a new branch typescript_chipper_1459_b

samreid commented 1 day ago

Current tsx patch:

```diff Subject: [PATCH] Revert multi-modal transpilation output, see https://github.com/phetsims/chipper/issues/1459 --- Index: chipper/js/grunt/.eslintrc.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/.eslintrc.js b/chipper/js/grunt/.eslintrc.js --- a/chipper/js/grunt/.eslintrc.js (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/js/grunt/.eslintrc.js (date 1726432631542) @@ -4,5 +4,31 @@ module.exports = { // Use all of the default rules from eslint file for node code. - extends: '../../../chipper/eslint/chipper_eslintrc.js' + extends: process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/eslint/chipper_eslintrc.js', + + parserOptions: { + sourceType: 'module' + }, + + overrides: [ { + files: [ '**/*.ts' ], + + parserOptions: { + + // Provide a tsconfig so that we can use rules that require type information. + // NOTE: Providing this slows down eslint substantially, see https://github.com/phetsims/chipper/issues/1114#issuecomment-1065927717 + + // IntelliJ runs this from chipper/js/grunt so the path is different than when running from chipper/, so we must normalize + // to support both IDE and command line + // for debugging here, you can put variables into the project then navigate to a file using this (like a *.ts file) + // and see the output in the bad path, or you can write to the file system. + project: [ process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/tsconfig/all/tsconfig.json' ] + }, + + // disable rules @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires + rules: { + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-var-requires': 'off' + } + } ] }; \ No newline at end of file Index: chipper/tsconfig/all/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/tsconfig/all/tsconfig.json b/chipper/tsconfig/all/tsconfig.json --- a/chipper/tsconfig/all/tsconfig.json (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/tsconfig/all/tsconfig.json (date 1726432639681) @@ -32,6 +32,7 @@ "../../../center-and-variability/images/**/*", "../../../chipper/phet-types.d.ts", "../../../chipper/phet-types-module.d.ts", + "../../../chipper/js/grunt/**/*", "../../../circuit-construction-kit-ac/js/**/*", "../../../circuit-construction-kit-ac-virtual-lab/js/**/*", "../../../circuit-construction-kit-common/js/**/*", Index: chipper/js/grunt/Gruntfile.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/Gruntfile.js b/chipper/js/grunt/Gruntfile.js --- a/chipper/js/grunt/Gruntfile.js (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/js/grunt/Gruntfile.js (date 1726433674747) @@ -12,6 +12,7 @@ const assert = require( 'assert' ); require( './checkNodeVersion' ); const child_process = require( 'child_process' ); +const fs = require( 'fs' ); const isWindows = /^win/.test( process.platform ); @@ -37,13 +38,29 @@ assert( typeof repo === 'string' && /^[a-z]+(-[a-z]+)*$/u.test( repo ), 'repo name should be composed of lower-case characters, optionally with dashes used as separators' ); function execTask( taskFilename ) { - const command = 'node'; + const command = '../chipper/node_modules/.bin/tsx'; return () => { spawn( command, [ `../chipper/js/grunt/tasks/${taskFilename}`, ...process.argv.slice( 2 ) ], process.cwd(), false ); }; } + /** + * Check for *.js and *.ts tasks and register them with Grunt. + */ + const registerForwardedTask = ( taskName, description ) => { + const tsExists = fs.existsSync( `../chipper/js/grunt/tasks/${taskName}.ts` ); + const jsExists = fs.existsSync( `../chipper/js/grunt/tasks/${taskName}.js` ); + + if ( tsExists && jsExists ) { + throw new Error( `Both TypeScript and JavaScript versions of the task ${taskName} exist. Please remove one of them.` ); + } + else { + const taskFilename = tsExists ? `${taskName}.ts` : `${taskName}.js`; + grunt.registerTask( taskName, description, execTask( taskFilename ) ); + } + }; + grunt.registerTask( 'default', 'Builds the repository', [ ...( grunt.option( 'lint' ) === false ? [] : [ 'lint-all' ] ), ...( grunt.option( 'report-media' ) === false ? [] : [ 'report-media' ] ), @@ -51,26 +68,16 @@ 'build' ] ); - grunt.registerTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory', - execTask( 'clean.js' ) - ); + registerForwardedTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory' ); - grunt.registerTask( 'build-images', 'Build images only', - execTask( 'build-images.js' ) - ); + registerForwardedTask( 'build-images', 'Build images only' ); - grunt.registerTask( 'output-js', 'Outputs JS just for the specified repo', - execTask( 'output-js.js' ) - ); - grunt.registerTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies', - execTask( 'output-js-project.js' ) - ); + registerForwardedTask( 'output-js', 'Outputs JS just for the specified repo' ); + registerForwardedTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies' ); - grunt.registerTask( 'output-js-all', 'Outputs JS for all repos', - execTask( 'output-js-all.js' ) - ); + registerForwardedTask( 'output-js-all', 'Outputs JS for all repos' ); - grunt.registerTask( 'build', + registerForwardedTask( 'build', `Builds the repository. Depending on the repository type (runnable/wrapper/standalone), the result may vary. Runnable build options: --report-media - Will iterate over all of the license.json files and reports any media files, set to false to opt out. @@ -89,130 +96,94 @@ --minify.mangle=false - During uglification, it will not "mangle" variable names (where they get renamed to short constants to reduce file size.) --minify.beautify=true - After uglification, the source code will be syntax formatted nicely --minify.stripAssertions=false - During uglification, it will strip assertions. - --minify.stripLogging=false - During uglification, it will not strip logging statements.`, - execTask( 'build.js' ) - ); + --minify.stripLogging=false - During uglification, it will not strip logging statements.` ); - grunt.registerTask( 'generate-used-strings-file', - 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode', - execTask( 'generate-used-strings-file.js' ) - ); + registerForwardedTask( 'generate-used-strings-file', + 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode' ); grunt.registerTask( 'build-for-server', 'meant for use by build-server only', [ 'build' ] ); - grunt.registerTask( 'lint', + registerForwardedTask( 'lint', `lint js files. Options: --disable-eslint-cache: cache will not be read from, and cache will be cleared for next run. --fix: autofixable changes will be written to disk --chip-away: output a list of responsible devs for each repo with lint problems ---repos: comma separated list of repos to lint in addition to the repo from running`, - execTask( 'lint.js' ) - ); +--repos: comma separated list of repos to lint in addition to the repo from running` ); - grunt.registerTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)', - execTask( 'lint-all.js' ) - ); + registerForwardedTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)' ); - grunt.registerTask( 'generate-development-html', - 'Generates top-level SIM_en.html file based on the preloads in package.json.', - execTask( 'generate-development-html.js' ) - ); + registerForwardedTask( 'generate-development-html', + 'Generates top-level SIM_en.html file based on the preloads in package.json.' ); - grunt.registerTask( 'generate-test-html', + registerForwardedTask( 'generate-test-html', 'Generates top-level SIM-tests.html file based on the preloads in package.json. See https://github.com/phetsims/aqua/blob/main/doc/adding-unit-tests.md ' + 'for more information on automated testing. Usually you should ' + - 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.', - execTask( 'generate-test-html.js' ) - ); + 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.' ); - grunt.registerTask( 'generate-a11y-view-html', + registerForwardedTask( 'generate-a11y-view-html', 'Generates top-level SIM-a11y-view.html file used for visualizing accessible content. Usually you should ' + 'set the "phet.simFeatures.supportsInteractiveDescription":true flag in the sim package.json and run `grunt update` ' + - 'instead of manually generating this.', - execTask( 'generate-a11y-view.js' ) - ); + 'instead of manually generating this.' ); - grunt.registerTask( 'update', ` + registerForwardedTask( 'update', ` Updates the normal automatically-generated files for this repository. Includes: * runnables: generate-development-html and modulify * accessible runnables: generate-a11y-view-html * unit tests: generate-test-html * simulations: generateREADME() * phet-io simulations: generate overrides file if needed - * create the conglomerate string files for unbuilt mode, for this repo and its dependencies`, - execTask( 'update.js' ) - ); + * create the conglomerate string files for unbuilt mode, for this repo and its dependencies` ); // This is not run in grunt update because it affects dependencies and outputs files outside of the repo. - grunt.registerTask( 'generate-development-strings', + registerForwardedTask( 'generate-development-strings', 'To support locales=* in unbuilt mode, generate a conglomerate JSON file for each repo with translations in babel. Run on all repos via:\n' + '* for-each.sh perennial-alias/data/active-repos npm install\n' + - '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings', - execTask( 'generate-development-strings.js' ) - ); + '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings' ); - grunt.registerTask( 'published-README', - 'Generates README.md file for a published simulation.', - execTask( 'published-README.js' ) - ); + registerForwardedTask( 'published-README', + 'Generates README.md file for a published simulation.' ); - grunt.registerTask( 'unpublished-README', - 'Generates README.md file for an unpublished simulation.', - execTask( 'unpublished-README.js' ) - ); + registerForwardedTask( 'unpublished-README', + 'Generates README.md file for an unpublished simulation.' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? - grunt.registerTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified', - execTask( 'sort-imports.js' ) - ); + registerForwardedTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt - grunt.registerTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.', - execTask( 'commits-since.js' ) - ); + registerForwardedTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.' ); // See reportMedia.js - grunt.registerTask( 'report-media', + registerForwardedTask( 'report-media', '(project-wide) Report on license.json files throughout all working copies. ' + 'Reports any media (such as images or sound) files that have any of the following problems:\n' + '(1) incompatible-license (resource license not approved)\n' + '(2) not-annotated (license.json missing or entry missing from license.json)\n' + - '(3) missing-file (entry in the license.json but not on the file system)', - execTask( 'report-media.js' ) - ); + '(3) missing-file (entry in the license.json but not on the file system)' ); // see reportThirdParty.js // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt - grunt.registerTask( 'report-third-party', + registerForwardedTask( 'report-third-party', 'Creates a report of third-party resources (code, images, sound, etc) used in the published PhET simulations by ' + 'reading the license information in published HTML files on the PhET website. This task must be run from main. ' + - 'After running this task, you must push sherpa/third-party-licenses.md.', - execTask( 'report-third-party.js' ) - ); + 'After running this task, you must push sherpa/third-party-licenses.md.' ); - grunt.registerTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo', - execTask( 'modulify.js' ) - ); + registerForwardedTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo' ); // Grunt task that determines created and last modified dates from git, and // updates copyright statements accordingly, see #403 - grunt.registerTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates', - execTask( 'update-copyright-dates.js' ) - ); + registerForwardedTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt, or maybe just delete? - grunt.registerTask( + registerForwardedTask( 'webpack-dev-server', `Runs a webpack server for a given list of simulations. --repos=REPOS for a comma-separated list of repos (defaults to current repo) --port=9000 to adjust the running port --devtool=string value for sourcemap generation specified at https://webpack.js.org/configuration/devtool or undefined for (none) - --chrome: open the sims in Chrome tabs (Mac)`, - execTask( 'webpack-dev-server.js' ) - ); + --chrome: open the sims in Chrome tabs (Mac)` ); - grunt.registerTask( + registerForwardedTask( 'generate-phet-io-api', 'Output the PhET-iO API as JSON to phet-io-sim-specific/api.\n' + 'Options\n:' + @@ -220,11 +191,9 @@ '--simList=... a file with a list of sims to compare (defaults to the sim in the current dir)\n' + '--stable - regenerate for all "stable sims" (see perennial/data/phet-io-api-stable/)\n' + '--temporary - outputs to the temporary directory\n' + - '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.', - execTask( 'generate-phet-io-api.js' ) - ); + '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.' ); - grunt.registerTask( + registerForwardedTask( 'compare-phet-io-api', 'Compares the phet-io-api against the reference version(s) if this sim\'s package.json marks compareDesignedAPIChanges. ' + 'This will by default compare designed changes only. Options:\n' + @@ -233,18 +202,12 @@ '--stable, generate the phet-io-apis for each phet-io sim considered to have a stable API (see perennial-alias/data/phet-io-api-stable)\n' + '--delta, by default a breaking-compatibility comparison is done, but --delta shows all changes\n' + '--temporary, compares API files in the temporary directory (otherwise compares to freshly generated APIs)\n' + - '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes', - execTask( 'compare-phet-io-api.js' ) - ); + '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? Search for docs in the code review checklist - grunt.registerTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo', - execTask( 'profile-file-size.js' ) - ); + registerForwardedTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo' ); - grunt.registerTask( 'test-grunt', 'Run tests for the Gruntfile', - execTask( 'test-grunt.js' ) - ); + registerForwardedTask( 'test-grunt', 'Run tests for the Gruntfile' ); /** * Creates grunt tasks that effectively get forwarded to perennial. It will execute a grunt process running from @@ -285,7 +248,7 @@ spawned.on( 'close', code => { if ( code !== 0 ) { - throw new Error( `perennial grunt ${argsString} failed with code ${code}` ); + throw new Error( `spawn: ${command} ${argsString} failed with code ${code}` ); } else { done(); Index: phetcommon/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phetcommon/tsconfig.json b/phetcommon/tsconfig.json --- a/phetcommon/tsconfig.json (revision 54b41ebbdddd743650d557910ec33b46b2b10317) +++ b/phetcommon/tsconfig.json (date 1726432639711) @@ -5,5 +5,8 @@ "images/**/*", "mipmaps/**/*", "sounds/**/*" - ] + ], + "compilerOptions": { + "allowSyntheticDefaultImports": true + } } \ No newline at end of file Index: chipper/js/grunt/tasks/build.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/tasks/build.js b/chipper/js/grunt/tasks/build.ts rename from chipper/js/grunt/tasks/build.js rename to chipper/js/grunt/tasks/build.ts --- a/chipper/js/grunt/tasks/build.js (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/js/grunt/tasks/build.ts (date 1726432619035) @@ -16,6 +16,8 @@ const grunt = require( 'grunt' ); const getRepo = require( './util/getRepo' ); + +// @ts-expect-error - overlaps with global assert in phet-types.d.ts TODO https://github.com/phetsims/chipper/issues/1459 const assert = require( 'assert' ); const Transpiler = require( '../../common/Transpiler' ); const getBrands = require( './util/getBrands' ); @@ -26,12 +28,12 @@ const transpiler = new Transpiler( { silent: true } ); -( async () => { +( async () => { /* eslint-disable-line @typescript-eslint/no-floating-promises */ // TODO: https://github.com/phetsims/chipper/issues/1459 ??? await phetTimingLog.startAsync( 'grunt-build', async () => { // Parse minification keys const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS ); - const minifyOptions = {}; + const minifyOptions: Record = {}; minifyKeys.forEach( minifyKey => { const option = getOption( `minify.${minifyKey}` ); if ( option === true || option === false ) { @@ -89,7 +91,7 @@ else { const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` ); - assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); + assert && assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); console.log( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` ); // Other options Index: chipper/package.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/package.json b/chipper/package.json --- a/chipper/package.json (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/package.json (date 1726432275147) @@ -59,6 +59,7 @@ "taffydb": "~2.7.3", "terser": "~4.6.4", "ts-morph": "^21.0.1", + "tsx": "~4.19.1", "typescript": "~5.5.4", "webpack": "~5.76.3", "webpack-cli": "~5.0.0", ```

next one just in case:

```diff Subject: [PATCH] Revert multi-modal transpilation output, see https://github.com/phetsims/chipper/issues/1459 --- Index: chipper/js/grunt/.eslintrc.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/.eslintrc.js b/chipper/js/grunt/.eslintrc.js --- a/chipper/js/grunt/.eslintrc.js (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/js/grunt/.eslintrc.js (date 1726432631542) @@ -4,5 +4,31 @@ module.exports = { // Use all of the default rules from eslint file for node code. - extends: '../../../chipper/eslint/chipper_eslintrc.js' + extends: process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/eslint/chipper_eslintrc.js', + + parserOptions: { + sourceType: 'module' + }, + + overrides: [ { + files: [ '**/*.ts' ], + + parserOptions: { + + // Provide a tsconfig so that we can use rules that require type information. + // NOTE: Providing this slows down eslint substantially, see https://github.com/phetsims/chipper/issues/1114#issuecomment-1065927717 + + // IntelliJ runs this from chipper/js/grunt so the path is different than when running from chipper/, so we must normalize + // to support both IDE and command line + // for debugging here, you can put variables into the project then navigate to a file using this (like a *.ts file) + // and see the output in the bad path, or you can write to the file system. + project: [ process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/tsconfig/all/tsconfig.json' ] + }, + + // disable rules @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires + rules: { + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-var-requires': 'off' + } + } ] }; \ No newline at end of file Index: chipper/tsconfig/all/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/tsconfig/all/tsconfig.json b/chipper/tsconfig/all/tsconfig.json --- a/chipper/tsconfig/all/tsconfig.json (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/tsconfig/all/tsconfig.json (date 1726432639681) @@ -32,6 +32,7 @@ "../../../center-and-variability/images/**/*", "../../../chipper/phet-types.d.ts", "../../../chipper/phet-types-module.d.ts", + "../../../chipper/js/grunt/**/*", "../../../circuit-construction-kit-ac/js/**/*", "../../../circuit-construction-kit-ac-virtual-lab/js/**/*", "../../../circuit-construction-kit-common/js/**/*", Index: chipper/js/grunt/Gruntfile.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/Gruntfile.js b/chipper/js/grunt/Gruntfile.js --- a/chipper/js/grunt/Gruntfile.js (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/js/grunt/Gruntfile.js (date 1726500244889) @@ -12,6 +12,7 @@ const assert = require( 'assert' ); require( './checkNodeVersion' ); const child_process = require( 'child_process' ); +const fs = require( 'fs' ); const isWindows = /^win/.test( process.platform ); @@ -37,13 +38,29 @@ assert( typeof repo === 'string' && /^[a-z]+(-[a-z]+)*$/u.test( repo ), 'repo name should be composed of lower-case characters, optionally with dashes used as separators' ); function execTask( taskFilename ) { - const command = 'node'; + const command = isWindows ? '../chipper/node_modules/.bin/tsx.cmd' : '../chipper/node_modules/.bin/tsx'; return () => { spawn( command, [ `../chipper/js/grunt/tasks/${taskFilename}`, ...process.argv.slice( 2 ) ], process.cwd(), false ); }; } + /** + * Check for *.js and *.ts tasks and register them with Grunt. + */ + const registerForwardedTask = ( taskName, description ) => { + const tsExists = fs.existsSync( `../chipper/js/grunt/tasks/${taskName}.ts` ); + const jsExists = fs.existsSync( `../chipper/js/grunt/tasks/${taskName}.js` ); + + if ( tsExists && jsExists ) { + throw new Error( `Both TypeScript and JavaScript versions of the task ${taskName} exist. Please remove one of them.` ); + } + else { + const taskFilename = tsExists ? `${taskName}.ts` : `${taskName}.js`; + grunt.registerTask( taskName, description, execTask( taskFilename ) ); + } + }; + grunt.registerTask( 'default', 'Builds the repository', [ ...( grunt.option( 'lint' ) === false ? [] : [ 'lint-all' ] ), ...( grunt.option( 'report-media' ) === false ? [] : [ 'report-media' ] ), @@ -51,26 +68,16 @@ 'build' ] ); - grunt.registerTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory', - execTask( 'clean.js' ) - ); + registerForwardedTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory' ); - grunt.registerTask( 'build-images', 'Build images only', - execTask( 'build-images.js' ) - ); + registerForwardedTask( 'build-images', 'Build images only' ); - grunt.registerTask( 'output-js', 'Outputs JS just for the specified repo', - execTask( 'output-js.js' ) - ); - grunt.registerTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies', - execTask( 'output-js-project.js' ) - ); + registerForwardedTask( 'output-js', 'Outputs JS just for the specified repo' ); + registerForwardedTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies' ); - grunt.registerTask( 'output-js-all', 'Outputs JS for all repos', - execTask( 'output-js-all.js' ) - ); + registerForwardedTask( 'output-js-all', 'Outputs JS for all repos' ); - grunt.registerTask( 'build', + registerForwardedTask( 'build', `Builds the repository. Depending on the repository type (runnable/wrapper/standalone), the result may vary. Runnable build options: --report-media - Will iterate over all of the license.json files and reports any media files, set to false to opt out. @@ -89,130 +96,94 @@ --minify.mangle=false - During uglification, it will not "mangle" variable names (where they get renamed to short constants to reduce file size.) --minify.beautify=true - After uglification, the source code will be syntax formatted nicely --minify.stripAssertions=false - During uglification, it will strip assertions. - --minify.stripLogging=false - During uglification, it will not strip logging statements.`, - execTask( 'build.js' ) - ); + --minify.stripLogging=false - During uglification, it will not strip logging statements.` ); - grunt.registerTask( 'generate-used-strings-file', - 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode', - execTask( 'generate-used-strings-file.js' ) - ); + registerForwardedTask( 'generate-used-strings-file', + 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode' ); grunt.registerTask( 'build-for-server', 'meant for use by build-server only', [ 'build' ] ); - grunt.registerTask( 'lint', + registerForwardedTask( 'lint', `lint js files. Options: --disable-eslint-cache: cache will not be read from, and cache will be cleared for next run. --fix: autofixable changes will be written to disk --chip-away: output a list of responsible devs for each repo with lint problems ---repos: comma separated list of repos to lint in addition to the repo from running`, - execTask( 'lint.js' ) - ); +--repos: comma separated list of repos to lint in addition to the repo from running` ); - grunt.registerTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)', - execTask( 'lint-all.js' ) - ); + registerForwardedTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)' ); - grunt.registerTask( 'generate-development-html', - 'Generates top-level SIM_en.html file based on the preloads in package.json.', - execTask( 'generate-development-html.js' ) - ); + registerForwardedTask( 'generate-development-html', + 'Generates top-level SIM_en.html file based on the preloads in package.json.' ); - grunt.registerTask( 'generate-test-html', + registerForwardedTask( 'generate-test-html', 'Generates top-level SIM-tests.html file based on the preloads in package.json. See https://github.com/phetsims/aqua/blob/main/doc/adding-unit-tests.md ' + 'for more information on automated testing. Usually you should ' + - 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.', - execTask( 'generate-test-html.js' ) - ); + 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.' ); - grunt.registerTask( 'generate-a11y-view-html', + registerForwardedTask( 'generate-a11y-view-html', 'Generates top-level SIM-a11y-view.html file used for visualizing accessible content. Usually you should ' + 'set the "phet.simFeatures.supportsInteractiveDescription":true flag in the sim package.json and run `grunt update` ' + - 'instead of manually generating this.', - execTask( 'generate-a11y-view.js' ) - ); + 'instead of manually generating this.' ); - grunt.registerTask( 'update', ` + registerForwardedTask( 'update', ` Updates the normal automatically-generated files for this repository. Includes: * runnables: generate-development-html and modulify * accessible runnables: generate-a11y-view-html * unit tests: generate-test-html * simulations: generateREADME() * phet-io simulations: generate overrides file if needed - * create the conglomerate string files for unbuilt mode, for this repo and its dependencies`, - execTask( 'update.js' ) - ); + * create the conglomerate string files for unbuilt mode, for this repo and its dependencies` ); // This is not run in grunt update because it affects dependencies and outputs files outside of the repo. - grunt.registerTask( 'generate-development-strings', + registerForwardedTask( 'generate-development-strings', 'To support locales=* in unbuilt mode, generate a conglomerate JSON file for each repo with translations in babel. Run on all repos via:\n' + '* for-each.sh perennial-alias/data/active-repos npm install\n' + - '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings', - execTask( 'generate-development-strings.js' ) - ); + '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings' ); - grunt.registerTask( 'published-README', - 'Generates README.md file for a published simulation.', - execTask( 'published-README.js' ) - ); + registerForwardedTask( 'published-README', + 'Generates README.md file for a published simulation.' ); - grunt.registerTask( 'unpublished-README', - 'Generates README.md file for an unpublished simulation.', - execTask( 'unpublished-README.js' ) - ); + registerForwardedTask( 'unpublished-README', + 'Generates README.md file for an unpublished simulation.' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? - grunt.registerTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified', - execTask( 'sort-imports.js' ) - ); + registerForwardedTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt - grunt.registerTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.', - execTask( 'commits-since.js' ) - ); + registerForwardedTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.' ); // See reportMedia.js - grunt.registerTask( 'report-media', + registerForwardedTask( 'report-media', '(project-wide) Report on license.json files throughout all working copies. ' + 'Reports any media (such as images or sound) files that have any of the following problems:\n' + '(1) incompatible-license (resource license not approved)\n' + '(2) not-annotated (license.json missing or entry missing from license.json)\n' + - '(3) missing-file (entry in the license.json but not on the file system)', - execTask( 'report-media.js' ) - ); + '(3) missing-file (entry in the license.json but not on the file system)' ); // see reportThirdParty.js // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt - grunt.registerTask( 'report-third-party', + registerForwardedTask( 'report-third-party', 'Creates a report of third-party resources (code, images, sound, etc) used in the published PhET simulations by ' + 'reading the license information in published HTML files on the PhET website. This task must be run from main. ' + - 'After running this task, you must push sherpa/third-party-licenses.md.', - execTask( 'report-third-party.js' ) - ); + 'After running this task, you must push sherpa/third-party-licenses.md.' ); - grunt.registerTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo', - execTask( 'modulify.js' ) - ); + registerForwardedTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo' ); // Grunt task that determines created and last modified dates from git, and // updates copyright statements accordingly, see #403 - grunt.registerTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates', - execTask( 'update-copyright-dates.js' ) - ); + registerForwardedTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt, or maybe just delete? - grunt.registerTask( + registerForwardedTask( 'webpack-dev-server', `Runs a webpack server for a given list of simulations. --repos=REPOS for a comma-separated list of repos (defaults to current repo) --port=9000 to adjust the running port --devtool=string value for sourcemap generation specified at https://webpack.js.org/configuration/devtool or undefined for (none) - --chrome: open the sims in Chrome tabs (Mac)`, - execTask( 'webpack-dev-server.js' ) - ); + --chrome: open the sims in Chrome tabs (Mac)` ); - grunt.registerTask( + registerForwardedTask( 'generate-phet-io-api', 'Output the PhET-iO API as JSON to phet-io-sim-specific/api.\n' + 'Options\n:' + @@ -220,11 +191,9 @@ '--simList=... a file with a list of sims to compare (defaults to the sim in the current dir)\n' + '--stable - regenerate for all "stable sims" (see perennial/data/phet-io-api-stable/)\n' + '--temporary - outputs to the temporary directory\n' + - '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.', - execTask( 'generate-phet-io-api.js' ) - ); + '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.' ); - grunt.registerTask( + registerForwardedTask( 'compare-phet-io-api', 'Compares the phet-io-api against the reference version(s) if this sim\'s package.json marks compareDesignedAPIChanges. ' + 'This will by default compare designed changes only. Options:\n' + @@ -233,18 +202,12 @@ '--stable, generate the phet-io-apis for each phet-io sim considered to have a stable API (see perennial-alias/data/phet-io-api-stable)\n' + '--delta, by default a breaking-compatibility comparison is done, but --delta shows all changes\n' + '--temporary, compares API files in the temporary directory (otherwise compares to freshly generated APIs)\n' + - '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes', - execTask( 'compare-phet-io-api.js' ) - ); + '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? Search for docs in the code review checklist - grunt.registerTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo', - execTask( 'profile-file-size.js' ) - ); + registerForwardedTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo' ); - grunt.registerTask( 'test-grunt', 'Run tests for the Gruntfile', - execTask( 'test-grunt.js' ) - ); + registerForwardedTask( 'test-grunt', 'Run tests for the Gruntfile' ); /** * Creates grunt tasks that effectively get forwarded to perennial. It will execute a grunt process running from @@ -285,7 +248,7 @@ spawned.on( 'close', code => { if ( code !== 0 ) { - throw new Error( `perennial grunt ${argsString} failed with code ${code}` ); + throw new Error( `spawn: ${command} ${argsString} failed with code ${code}` ); } else { done(); Index: phetcommon/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/phetcommon/tsconfig.json b/phetcommon/tsconfig.json --- a/phetcommon/tsconfig.json (revision 54b41ebbdddd743650d557910ec33b46b2b10317) +++ b/phetcommon/tsconfig.json (date 1726432639711) @@ -5,5 +5,8 @@ "images/**/*", "mipmaps/**/*", "sounds/**/*" - ] + ], + "compilerOptions": { + "allowSyntheticDefaultImports": true + } } \ No newline at end of file Index: chipper/js/grunt/tasks/build.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/tasks/build.js b/chipper/js/grunt/tasks/build.ts rename from chipper/js/grunt/tasks/build.js rename to chipper/js/grunt/tasks/build.ts --- a/chipper/js/grunt/tasks/build.js (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/js/grunt/tasks/build.ts (date 1726432619035) @@ -16,6 +16,8 @@ const grunt = require( 'grunt' ); const getRepo = require( './util/getRepo' ); + +// @ts-expect-error - overlaps with global assert in phet-types.d.ts TODO https://github.com/phetsims/chipper/issues/1459 const assert = require( 'assert' ); const Transpiler = require( '../../common/Transpiler' ); const getBrands = require( './util/getBrands' ); @@ -26,12 +28,12 @@ const transpiler = new Transpiler( { silent: true } ); -( async () => { +( async () => { /* eslint-disable-line @typescript-eslint/no-floating-promises */ // TODO: https://github.com/phetsims/chipper/issues/1459 ??? await phetTimingLog.startAsync( 'grunt-build', async () => { // Parse minification keys const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS ); - const minifyOptions = {}; + const minifyOptions: Record = {}; minifyKeys.forEach( minifyKey => { const option = getOption( `minify.${minifyKey}` ); if ( option === true || option === false ) { @@ -89,7 +91,7 @@ else { const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` ); - assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); + assert && assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); console.log( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` ); // Other options Index: chipper/package.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/package.json b/chipper/package.json --- a/chipper/package.json (revision 2830dad88e127976237f550a7428a827ab87f8ce) +++ b/chipper/package.json (date 1726432275147) @@ -59,6 +59,7 @@ "taffydb": "~2.7.3", "terser": "~4.6.4", "ts-morph": "^21.0.1", + "tsx": "~4.19.1", "typescript": "~5.5.4", "webpack": "~5.76.3", "webpack-cli": "~5.0.0",
samreid commented 1 day ago

Dynamically discover task names and parse doc:

```diff Subject: [PATCH] Add notes, see https://github.com/phetsims/chipper/issues/1461 --- Index: js/grunt/Gruntfile.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/Gruntfile.js b/js/grunt/Gruntfile.js --- a/js/grunt/Gruntfile.js (revision 79e88551b1bbdc778a5c4bf40e7f4070486b3cde) +++ b/js/grunt/Gruntfile.js (date 1726516724954) @@ -12,6 +12,7 @@ const assert = require( 'assert' ); require( './checkNodeVersion' ); const child_process = require( 'child_process' ); +const fs = require( 'fs' ); const isWindows = /^win/.test( process.platform ); @@ -44,124 +45,158 @@ }; } + const elements = fs.readdirSync( __dirname + '/tasks' ); + console.log( elements ); + + elements.forEach( element => { + if ( element.endsWith( '.js' ) || element.endsWith( '.ts' ) ) { + + const taskName = element.substring( 0, element.lastIndexOf( '.' ) ); + + let myDoc = 'test'; + try { + // const myTask = require( `./tasks/${element}` ); + + + const source = fs.readFileSync( __dirname + `/tasks/${element}`, { encoding: 'utf-8' } ); + myDoc = source.substring( source.indexOf( '/**' ), source.indexOf( '*/' ) ); + + // myDoc = myTask.doc; + } + catch( e ) {} + + console.log( taskName ); + console.log( myDoc ); + + console.log( 'register task: ' + element ); + grunt.registerTask( taskName, myDoc, + execTask( element ) + ); + } + } ); + // list files sync from tasks/ + // grunt.file.expand( 'tasks/*.js' ).forEach( taskFilename => { + // console.log( 'hello' ) + // } ); + grunt.registerTask( 'default', 'Builds the repository', [ ...( grunt.option( 'lint' ) === false ? [] : [ 'lint-all' ] ), ...( grunt.option( 'report-media' ) === false ? [] : [ 'report-media' ] ), 'clean', 'build' ] ); - - grunt.registerTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory', - execTask( 'clean.js' ) - ); - - grunt.registerTask( 'build-images', 'Build images only', - execTask( 'build-images.js' ) - ); - - grunt.registerTask( 'output-js', 'Outputs JS just for the specified repo', - execTask( 'output-js.js' ) - ); - grunt.registerTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies', - execTask( 'output-js-project.js' ) - ); - - grunt.registerTask( 'output-js-all', 'Outputs JS for all repos', - execTask( 'output-js-all.js' ) - ); - - grunt.registerTask( 'build', - `Builds the repository. Depending on the repository type (runnable/wrapper/standalone), the result may vary. -Runnable build options: - --report-media - Will iterate over all of the license.json files and reports any media files, set to false to opt out. - --brands={{BRANDS} - Can be * (build all supported brands), or a comma-separated list of brand names. Will fall back to using - build-local.json's brands (or adapted-from-phet if that does not exist) - --XHTML - Includes an xhtml/ directory in the build output that contains a runnable XHTML form of the sim (with - a separated-out JS file). - --locales={{LOCALES}} - Can be * (build all available locales, "en" and everything in babel), or a comma-separated list of locales - --noTranspile - Flag to opt out of transpiling repos before build. This should only be used if you are confident that chipper/dist is already correct (to save time). - --noTSC - Flag to opt out of type checking before build. This should only be used if you are confident that TypeScript is already errorless (to save time). - --encodeStringMap=false - Disables the encoding of the string map in the built file. This is useful for debugging. - -Minify-specific options: - --minify.babelTranspile=false - Disables babel transpilation phase. - --minify.uglify=false - Disables uglification, so the built file will include (essentially) concatenated source files. - --minify.mangle=false - During uglification, it will not "mangle" variable names (where they get renamed to short constants to reduce file size.) - --minify.beautify=true - After uglification, the source code will be syntax formatted nicely - --minify.stripAssertions=false - During uglification, it will strip assertions. - --minify.stripLogging=false - During uglification, it will not strip logging statements.`, - execTask( 'build.js' ) - ); - - grunt.registerTask( 'generate-used-strings-file', - 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode', - execTask( 'generate-used-strings-file.js' ) - ); +// +// grunt.registerTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory', +// execTask( 'clean.js' ) +// ); +// +// grunt.registerTask( 'build-images', 'Build images only', +// execTask( 'build-images.js' ) +// ); +// +// grunt.registerTask( 'output-js', 'Outputs JS just for the specified repo', +// execTask( 'output-js.js' ) +// ); +// grunt.registerTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies', +// execTask( 'output-js-project.js' ) +// ); +// +// grunt.registerTask( 'output-js-all', 'Outputs JS for all repos', +// execTask( 'output-js-all.js' ) +// ); +// +// grunt.registerTask( 'build', +// `Builds the repository. Depending on the repository type (runnable/wrapper/standalone), the result may vary. +// Runnable build options: +// --report-media - Will iterate over all of the license.json files and reports any media files, set to false to opt out. +// --brands={{BRANDS} - Can be * (build all supported brands), or a comma-separated list of brand names. Will fall back to using +// build-local.json's brands (or adapted-from-phet if that does not exist) +// --XHTML - Includes an xhtml/ directory in the build output that contains a runnable XHTML form of the sim (with +// a separated-out JS file). +// --locales={{LOCALES}} - Can be * (build all available locales, "en" and everything in babel), or a comma-separated list of locales +// --noTranspile - Flag to opt out of transpiling repos before build. This should only be used if you are confident that chipper/dist is already correct (to save time). +// --noTSC - Flag to opt out of type checking before build. This should only be used if you are confident that TypeScript is already errorless (to save time). +// --encodeStringMap=false - Disables the encoding of the string map in the built file. This is useful for debugging. +// +// Minify-specific options: +// --minify.babelTranspile=false - Disables babel transpilation phase. +// --minify.uglify=false - Disables uglification, so the built file will include (essentially) concatenated source files. +// --minify.mangle=false - During uglification, it will not "mangle" variable names (where they get renamed to short constants to reduce file size.) +// --minify.beautify=true - After uglification, the source code will be syntax formatted nicely +// --minify.stripAssertions=false - During uglification, it will strip assertions. +// --minify.stripLogging=false - During uglification, it will not strip logging statements.`, +// execTask( 'build.js' ) +// ); +// +// grunt.registerTask( 'generate-used-strings-file', +// 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode', +// execTask( 'generate-used-strings-file.js' ) +// ); grunt.registerTask( 'build-for-server', 'meant for use by build-server only', [ 'build' ] ); - grunt.registerTask( 'lint', - `lint js files. Options: ---disable-eslint-cache: cache will not be read from, and cache will be cleared for next run. ---fix: autofixable changes will be written to disk ---chip-away: output a list of responsible devs for each repo with lint problems ---repos: comma separated list of repos to lint in addition to the repo from running`, - execTask( 'lint.js' ) - ); +// grunt.registerTask( 'lint', +// `lint js files. Options: +// --disable-eslint-cache: cache will not be read from, and cache will be cleared for next run. +// --fix: autofixable changes will be written to disk +// --chip-away: output a list of responsible devs for each repo with lint problems +// --repos: comma separated list of repos to lint in addition to the repo from running`, +// execTask( 'lint.js' ) +// ); - grunt.registerTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)', - execTask( 'lint-all.js' ) - ); + // grunt.registerTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)', + // execTask( 'lint-all.js' ) + // ); - grunt.registerTask( 'generate-development-html', - 'Generates top-level SIM_en.html file based on the preloads in package.json.', - execTask( 'generate-development-html.js' ) - ); + // grunt.registerTask( 'generate-development-html', + // 'Generates top-level SIM_en.html file based on the preloads in package.json.', + // execTask( 'generate-development-html.js' ) + // ); - grunt.registerTask( 'generate-test-html', - 'Generates top-level SIM-tests.html file based on the preloads in package.json. See https://github.com/phetsims/aqua/blob/main/doc/adding-unit-tests.md ' + - 'for more information on automated testing. Usually you should ' + - 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.', - execTask( 'generate-test-html.js' ) - ); + // grunt.registerTask( 'generate-test-html', + // 'Generates top-level SIM-tests.html file based on the preloads in package.json. See https://github.com/phetsims/aqua/blob/main/doc/adding-unit-tests.md ' + + // 'for more information on automated testing. Usually you should ' + + // 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.', + // execTask( 'generate-test-html.js' ) + // ); - grunt.registerTask( 'generate-a11y-view-html', - 'Generates top-level SIM-a11y-view.html file used for visualizing accessible content. Usually you should ' + - 'set the "phet.simFeatures.supportsInteractiveDescription":true flag in the sim package.json and run `grunt update` ' + - 'instead of manually generating this.', - execTask( 'generate-a11y-view.js' ) - ); + // grunt.registerTask( 'generate-a11y-view-html', + // 'Generates top-level SIM-a11y-view.html file used for visualizing accessible content. Usually you should ' + + // 'set the "phet.simFeatures.supportsInteractiveDescription":true flag in the sim package.json and run `grunt update` ' + + // 'instead of manually generating this.', + // execTask( 'generate-a11y-view.js' ) + // ); - grunt.registerTask( 'update', ` -Updates the normal automatically-generated files for this repository. Includes: - * runnables: generate-development-html and modulify - * accessible runnables: generate-a11y-view-html - * unit tests: generate-test-html - * simulations: generateREADME() - * phet-io simulations: generate overrides file if needed - * create the conglomerate string files for unbuilt mode, for this repo and its dependencies`, - execTask( 'update.js' ) - ); +// grunt.registerTask( 'update', ` +// Updates the normal automatically-generated files for this repository. Includes: +// * runnables: generate-development-html and modulify +// * accessible runnables: generate-a11y-view-html +// * unit tests: generate-test-html +// * simulations: generateREADME() +// * phet-io simulations: generate overrides file if needed +// * create the conglomerate string files for unbuilt mode, for this repo and its dependencies`, +// execTask( 'update.js' ) +// ); // This is not run in grunt update because it affects dependencies and outputs files outside of the repo. - grunt.registerTask( 'generate-development-strings', - 'To support locales=* in unbuilt mode, generate a conglomerate JSON file for each repo with translations in babel. Run on all repos via:\n' + - '* for-each.sh perennial-alias/data/active-repos npm install\n' + - '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings', - execTask( 'generate-development-strings.js' ) - ); + // grunt.registerTask( 'generate-development-strings', + // 'To support locales=* in unbuilt mode, generate a conglomerate JSON file for each repo with translations in babel. Run on all repos via:\n' + + // '* for-each.sh perennial-alias/data/active-repos npm install\n' + + // '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings', + // execTask( 'generate-development-strings.js' ) + // ); - grunt.registerTask( 'published-README', - 'Generates README.md file for a published simulation.', - execTask( 'published-README.js' ) - ); + // grunt.registerTask( 'published-README', + // 'Generates README.md file for a published simulation.', + // execTask( 'published-README.js' ) + // ); - grunt.registerTask( 'unpublished-README', - 'Generates README.md file for an unpublished simulation.', - execTask( 'unpublished-README.js' ) - ); + // grunt.registerTask( 'unpublished-README', + // 'Generates README.md file for an unpublished simulation.', + // execTask( 'unpublished-README.js' ) + // ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? // AV would like a way to sort the imports, OK if it is a grunt script or node script. As long as there way to do it. @@ -171,92 +206,92 @@ // MK: Make an issue to make the sort by module part of the code style. Reformat the codebase by that style. // MK: All opposed? // MK: is working on it. - grunt.registerTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified', - execTask( 'sort-imports.js' ) - ); + // grunt.registerTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified', + // execTask( 'sort-imports.js' ) + // ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt // SR, AV, JB, MK, JG do not use it. We will check with @pixelzoom to see if it is OK to move to node. // MK: But it is nice having a central registry + pattern for "things we run in sim/common repos" - grunt.registerTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.', - execTask( 'commits-since.js' ) - ); + // grunt.registerTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.', + // execTask( 'commits-since.js' ) + // ); // See reportMedia.js - grunt.registerTask( 'report-media', - '(project-wide) Report on license.json files throughout all working copies. ' + - 'Reports any media (such as images or sound) files that have any of the following problems:\n' + - '(1) incompatible-license (resource license not approved)\n' + - '(2) not-annotated (license.json missing or entry missing from license.json)\n' + - '(3) missing-file (entry in the license.json but not on the file system)', - execTask( 'report-media.js' ) - ); + // grunt.registerTask( 'report-media', + // '(project-wide) Report on license.json files throughout all working copies. ' + + // 'Reports any media (such as images or sound) files that have any of the following problems:\n' + + // '(1) incompatible-license (resource license not approved)\n' + + // '(2) not-annotated (license.json missing or entry missing from license.json)\n' + + // '(3) missing-file (entry in the license.json but not on the file system)', + // execTask( 'report-media.js' ) + // ); // see reportThirdParty.js // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt - grunt.registerTask( 'report-third-party', - 'Creates a report of third-party resources (code, images, sound, etc) used in the published PhET simulations by ' + - 'reading the license information in published HTML files on the PhET website. This task must be run from main. ' + - 'After running this task, you must push sherpa/third-party-licenses.md.', - execTask( 'report-third-party.js' ) - ); + // grunt.registerTask( 'report-third-party', + // 'Creates a report of third-party resources (code, images, sound, etc) used in the published PhET simulations by ' + + // 'reading the license information in published HTML files on the PhET website. This task must be run from main. ' + + // 'After running this task, you must push sherpa/third-party-licenses.md.', + // execTask( 'report-third-party.js' ) + // ); - grunt.registerTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo', - execTask( 'modulify.js' ) - ); + // grunt.registerTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo', + // execTask( 'modulify.js' ) + // ); // Grunt task that determines created and last modified dates from git, and // updates copyright statements accordingly, see #403 - grunt.registerTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates', - execTask( 'update-copyright-dates.js' ) - ); + // grunt.registerTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates', + // execTask( 'update-copyright-dates.js' ) + // ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt, or maybe just delete? // Dev meeting consensus: DELETE - grunt.registerTask( - 'webpack-dev-server', `Runs a webpack server for a given list of simulations. - --repos=REPOS for a comma-separated list of repos (defaults to current repo) - --port=9000 to adjust the running port - --devtool=string value for sourcemap generation specified at https://webpack.js.org/configuration/devtool or undefined for (none) - --chrome: open the sims in Chrome tabs (Mac)`, - execTask( 'webpack-dev-server.js' ) - ); + // grunt.registerTask( + // 'webpack-dev-server', `Runs a webpack server for a given list of simulations. + // --repos=REPOS for a comma-separated list of repos (defaults to current repo) + // --port=9000 to adjust the running port + // --devtool=string value for sourcemap generation specified at https://webpack.js.org/configuration/devtool or undefined for (none) + // --chrome: open the sims in Chrome tabs (Mac)`, + // execTask( 'webpack-dev-server.js' ) + // ); - grunt.registerTask( - 'generate-phet-io-api', - 'Output the PhET-iO API as JSON to phet-io-sim-specific/api.\n' + - 'Options\n:' + - '--sims=... a list of sims to compare (defaults to the sim in the current dir)\n' + - '--simList=... a file with a list of sims to compare (defaults to the sim in the current dir)\n' + - '--stable - regenerate for all "stable sims" (see perennial/data/phet-io-api-stable/)\n' + - '--temporary - outputs to the temporary directory\n' + - '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.', - execTask( 'generate-phet-io-api.js' ) - ); + // grunt.registerTask( + // 'generate-phet-io-api', + // 'Output the PhET-iO API as JSON to phet-io-sim-specific/api.\n' + + // 'Options\n:' + + // '--sims=... a list of sims to compare (defaults to the sim in the current dir)\n' + + // '--simList=... a file with a list of sims to compare (defaults to the sim in the current dir)\n' + + // '--stable - regenerate for all "stable sims" (see perennial/data/phet-io-api-stable/)\n' + + // '--temporary - outputs to the temporary directory\n' + + // '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.', + // execTask( 'generate-phet-io-api.js' ) + // ); - grunt.registerTask( - 'compare-phet-io-api', - 'Compares the phet-io-api against the reference version(s) if this sim\'s package.json marks compareDesignedAPIChanges. ' + - 'This will by default compare designed changes only. Options:\n' + - '--sims=... a list of sims to compare (defaults to the sim in the current dir)\n' + - '--simList=... a file with a list of sims to compare (defaults to the sim in the current dir)\n' + - '--stable, generate the phet-io-apis for each phet-io sim considered to have a stable API (see perennial-alias/data/phet-io-api-stable)\n' + - '--delta, by default a breaking-compatibility comparison is done, but --delta shows all changes\n' + - '--temporary, compares API files in the temporary directory (otherwise compares to freshly generated APIs)\n' + - '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes', - execTask( 'compare-phet-io-api.js' ) - ); + // grunt.registerTask( + // 'compare-phet-io-api', + // 'Compares the phet-io-api against the reference version(s) if this sim\'s package.json marks compareDesignedAPIChanges. ' + + // 'This will by default compare designed changes only. Options:\n' + + // '--sims=... a list of sims to compare (defaults to the sim in the current dir)\n' + + // '--simList=... a file with a list of sims to compare (defaults to the sim in the current dir)\n' + + // '--stable, generate the phet-io-apis for each phet-io sim considered to have a stable API (see perennial-alias/data/phet-io-api-stable)\n' + + // '--delta, by default a breaking-compatibility comparison is done, but --delta shows all changes\n' + + // '--temporary, compares API files in the temporary directory (otherwise compares to freshly generated APIs)\n' + + // '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes', + // execTask( 'compare-phet-io-api.js' ) + // ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? Search for docs in the code review checklist // Dev team consensus: move to node. Run like this: `node ../chipper/js/scripts/profile-file-size.js` // TODO: Add to code review checklist, see https://github.com/phetsims/chipper/issues/1461 - grunt.registerTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo', - execTask( 'profile-file-size.js' ) - ); + // grunt.registerTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo', + // execTask( 'profile-file-size.js' ) + // ); - grunt.registerTask( 'test-grunt', 'Run tests for the Gruntfile', - execTask( 'test-grunt.js' ) - ); + // grunt.registerTask( 'test-grunt', 'Run tests for the Gruntfile', + // execTask( 'test-grunt.js' ) + // ); /** * Creates grunt tasks that effectively get forwarded to perennial. It will execute a grunt process running from Index: js/grunt/tasks/build.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/build.js b/js/grunt/tasks/build.js --- a/js/grunt/tasks/build.js (revision 79e88551b1bbdc778a5c4bf40e7f4070486b3cde) +++ b/js/grunt/tasks/build.js (date 1726516444256) @@ -1,9 +1,28 @@ // Copyright 2024, University of Colorado Boulder /** + * Builds the repository. Depending on the repository type (runnable/wrapper/standalone), the result may vary. + * Runnable build options: + * --report-media - Will iterate over all of the license.json files and reports any media files, set to false to opt out. + * --brands={{BRANDS} - Can be * (build all supported brands), or a comma-separated list of brand names. Will fall back to using + * build-local.json's brands (or adapted-from-phet if that does not exist) + * --XHTML - Includes an xhtml/ directory in the build output that contains a runnable XHTML form of the sim (with + * a separated-out JS file). + * --locales={{LOCALES}} - Can be * (build all available locales, "en" and everything in babel), or a comma-separated list of locales + * --noTranspile - Flag to opt out of transpiling repos before build. This should only be used if you are confident that chipper/dist is already correct (to save time). + * --noTSC - Flag to opt out of type checking before build. This should only be used if you are confident that TypeScript is already errorless (to save time). + * --encodeStringMap=false - Disables the encoding of the string map in the built file. This is useful for debugging. + * + * Minify-specific options: + * --minify.babelTranspile=false - Disables babel transpilation phase. + * --minify.uglify=false - Disables uglification, so the built file will include (essentially) concatenated source files. + * --minify.mangle=false - During uglification, it will not "mangle" variable names (where they get renamed to short constants to reduce file size.) + * --minify.beautify=true - After uglification, the source code will be syntax formatted nicely + * --minify.stripAssertions=false - During uglification, it will strip assertions. + * --minify.stripLogging=false - During uglification, it will not strip logging statements. + * * @author Sam Reid (PhET Interactive Simulations) */ - const buildStandalone = require( '../buildStandalone' ); const buildRunnable = require( '../buildRunnable' ); const minify = require( '../minify' ); @@ -108,4 +127,14 @@ } } } ); -} )(); \ No newline at end of file +} )(); + +module.exports = { + myFunc: ()=>{}, + doc: 'whats up doc' +}; + +/// command line: +// run myfunc +// +// else \ No newline at end of file
zepumph commented 1 day ago
``` Subject: [PATCH] fdsa --- Index: chipper/package.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/package.json b/chipper/package.json --- a/chipper/package.json (revision 79e88551b1bbdc778a5c4bf40e7f4070486b3cde) +++ b/chipper/package.json (date 1726519288941) @@ -59,6 +59,7 @@ "taffydb": "~2.7.3", "terser": "~4.6.4", "ts-morph": "^21.0.1", + "tsx": "~4.19.1", "typescript": "~5.5.4", "webpack": "~5.76.3", "webpack-cli": "~5.0.0", Index: chipper/js/grunt/tasks/build.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/tasks/build.js b/chipper/js/grunt/tasks/build.ts rename from chipper/js/grunt/tasks/build.js rename to chipper/js/grunt/tasks/build.ts --- a/chipper/js/grunt/tasks/build.js (revision 79e88551b1bbdc778a5c4bf40e7f4070486b3cde) +++ b/chipper/js/grunt/tasks/build.ts (date 1726519273303) @@ -16,22 +16,27 @@ const grunt = require( 'grunt' ); const getRepo = require( './util/getRepo' ); + +// @ts-expect-error - overlaps with global assert in phet-types.d.ts TODO https://github.com/phetsims/chipper/issues/1459 const assert = require( 'assert' ); const Transpiler = require( '../../common/Transpiler' ); const getBrands = require( './util/getBrands' ); const getOption = require( './util/getOption' ); const buildLocal = require( './util/buildLocal' ); - +global.hello = true; const repo = getRepo(); +console.log( document.createElement( 'div' ) ); +console.log( process.env ); const transpiler = new Transpiler( { silent: true } ); -( async () => { +( async () => { /* eslint-disable-line @typescript-eslint/no-floating-promises */ // TODO: https://github.com/phetsims/chipper/issues/1459 ??? await phetTimingLog.startAsync( 'grunt-build', async () => { + const x: number = 'hi'; // Parse minification keys const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS ); - const minifyOptions = {}; + const minifyOptions: Record = {}; minifyKeys.forEach( minifyKey => { const option = getOption( `minify.${minifyKey}` ); if ( option === true || option === false ) { @@ -89,7 +94,7 @@ else { const localPackageObject = grunt.file.readJSON( `../${repo}/package.json` ); - assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); + assert && assert( localPackageObject.phet.runnable, `${repo} does not appear to be runnable` ); console.log( `Building runnable repository (${repo}, brands: ${brands.join( ', ' )})` ); // Other options Index: perennial/js/common/checkoutMain.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/perennial/js/common/checkoutMain.ts b/perennial/js/common/checkoutMain.ts new file mode 100644 --- /dev/null (date 1726519273307) +++ b/perennial/js/common/checkoutMain.ts (date 1726519273307) @@ -0,0 +1,40 @@ +// Copyright 2017, University of Colorado Boulder + +/** + * Checks out main for a repository and all of its dependencies. + * + * @author Jonathan Olson + */ + +const getDependencies = require( './getDependencies' ); +const gitCheckout = require( './gitCheckout' ); +const npmUpdate = require( './npmUpdate' ); +const winston = require( 'winston' ); + +console.log( process.env ); +/** + * Checks out main for a repository and all of its dependencies. + * @public + * + * @param {string} repo - The repository name + * @param {boolean} includeNpmUpdate - Whether npm updates should be done to repositories. + * @returns {Promise} + */ +module.exports = async function( repo: string, includeNpmUpdate: boolean ) { + winston.info( `checking out main for ${repo}` ); + + const dependencies = await getDependencies( repo ); + + // Ignore the comment + const repoNames = Object.keys( dependencies ).filter( key => key !== 'comment' ); + + for ( const repoName of repoNames ) { + await gitCheckout( repoName, 'main' ); + } + + if ( includeNpmUpdate ) { + await npmUpdate( repo ); + await npmUpdate( 'chipper' ); + await npmUpdate( 'perennial-alias' ); + } +}; \ No newline at end of file Index: density/js/density-main.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/density/js/density-main.ts b/density/js/density-main.ts --- a/density/js/density-main.ts (revision 971654cfe8756d963f023fd28638ea56c17e903e) +++ b/density/js/density-main.ts (date 1726519273310) @@ -23,6 +23,10 @@ import DensityBuoyancyCommonQueryParameters from '../../density-buoyancy-common/js/common/DensityBuoyancyCommonQueryParameters.js'; import DensityBuoyancyCommonCredits from '../../density-buoyancy-common/js/common/DensityBuoyancyCommonCredits.js'; +console.log( process.env ); +console.log( global.hi ); +console.log( window.hi ); +console.log( window.location ); const simOptions: SimOptions = { credits: DensityBuoyancyCommonCredits, webgl: true, Index: chipper/tsconfig/all/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/tsconfig/all/tsconfig.json b/chipper/tsconfig/all/tsconfig.json --- a/chipper/tsconfig/all/tsconfig.json (revision 79e88551b1bbdc778a5c4bf40e7f4070486b3cde) +++ b/chipper/tsconfig/all/tsconfig.json (date 1726517748630) @@ -32,6 +32,7 @@ "../../../center-and-variability/images/**/*", "../../../chipper/phet-types.d.ts", "../../../chipper/phet-types-module.d.ts", + "../../../chipper/js/grunt/**/*", "../../../circuit-construction-kit-ac/js/**/*", "../../../circuit-construction-kit-ac-virtual-lab/js/**/*", "../../../circuit-construction-kit-common/js/**/*", Index: chipper/js/grunt/Gruntfile.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/Gruntfile.js b/chipper/js/grunt/Gruntfile.js --- a/chipper/js/grunt/Gruntfile.js (revision 79e88551b1bbdc778a5c4bf40e7f4070486b3cde) +++ b/chipper/js/grunt/Gruntfile.js (date 1726518397855) @@ -12,6 +12,8 @@ const assert = require( 'assert' ); require( './checkNodeVersion' ); const child_process = require( 'child_process' ); +const fs = require( 'fs' ); +const path = require( 'path' ); const isWindows = /^win/.test( process.platform ); @@ -37,12 +39,28 @@ assert( typeof repo === 'string' && /^[a-z]+(-[a-z]+)*$/u.test( repo ), 'repo name should be composed of lower-case characters, optionally with dashes used as separators' ); function execTask( taskFilename ) { - const command = 'node'; + const command = `${path.join( '..', 'chipper', 'node_modules', '.bin', 'tsx' )}${isWindows ? '.cmd' : ''}`; return () => { - spawn( command, [ `../chipper/js/grunt/tasks/${taskFilename}`, ...process.argv.slice( 2 ) ], process.cwd(), false ); + spawn( command, [ `../chipper/js/grunt/tasks/${taskFilename}`, ...process.argv.slice( 2 ) ], process.cwd(), true ); }; } + + /** + * Check for *.js and *.ts tasks and register them with Grunt. + */ + const registerForwardedTask = ( taskName, description ) => { + const tsExists = fs.existsSync( `../chipper/js/grunt/tasks/${taskName}.ts` ); + const jsExists = fs.existsSync( `../chipper/js/grunt/tasks/${taskName}.js` ); + + if ( tsExists && jsExists ) { + throw new Error( `Both TypeScript and JavaScript versions of the task ${taskName} exist. Please remove one of them.` ); + } + else { + const taskFilename = tsExists ? `${taskName}.ts` : `${taskName}.js`; + grunt.registerTask( taskName, description, execTask( taskFilename ) ); + } + }; grunt.registerTask( 'default', 'Builds the repository', [ ...( grunt.option( 'lint' ) === false ? [] : [ 'lint-all' ] ), @@ -51,26 +69,16 @@ 'build' ] ); - grunt.registerTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory', - execTask( 'clean.js' ) - ); + registerForwardedTask( 'clean', 'Erases the build/ directory and all its contents, and recreates the build/ directory' ); - grunt.registerTask( 'build-images', 'Build images only', - execTask( 'build-images.js' ) - ); + registerForwardedTask( 'build-images', 'Build images only' ); - grunt.registerTask( 'output-js', 'Outputs JS just for the specified repo', - execTask( 'output-js.js' ) - ); - grunt.registerTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies', - execTask( 'output-js-project.js' ) - ); + registerForwardedTask( 'output-js', 'Outputs JS just for the specified repo' ); + registerForwardedTask( 'output-js-project', 'Outputs JS for the specified repo and its dependencies' ); - grunt.registerTask( 'output-js-all', 'Outputs JS for all repos', - execTask( 'output-js-all.js' ) - ); + registerForwardedTask( 'output-js-all', 'Outputs JS for all repos' ); - grunt.registerTask( 'build', + registerForwardedTask( 'build', `Builds the repository. Depending on the repository type (runnable/wrapper/standalone), the result may vary. Runnable build options: --report-media - Will iterate over all of the license.json files and reports any media files, set to false to opt out. @@ -89,79 +97,57 @@ --minify.mangle=false - During uglification, it will not "mangle" variable names (where they get renamed to short constants to reduce file size.) --minify.beautify=true - After uglification, the source code will be syntax formatted nicely --minify.stripAssertions=false - During uglification, it will strip assertions. - --minify.stripLogging=false - During uglification, it will not strip logging statements.`, - execTask( 'build.js' ) - ); + --minify.stripLogging=false - During uglification, it will not strip logging statements.` ); - grunt.registerTask( 'generate-used-strings-file', - 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode', - execTask( 'generate-used-strings-file.js' ) - ); + registerForwardedTask( 'generate-used-strings-file', + 'Writes used strings to phet-io-sim-specific/ so that PhET-iO sims only output relevant strings to the API in unbuilt mode' ); grunt.registerTask( 'build-for-server', 'meant for use by build-server only', [ 'build' ] ); - grunt.registerTask( 'lint', + registerForwardedTask( 'lint', `lint js files. Options: --disable-eslint-cache: cache will not be read from, and cache will be cleared for next run. --fix: autofixable changes will be written to disk --chip-away: output a list of responsible devs for each repo with lint problems ---repos: comma separated list of repos to lint in addition to the repo from running`, - execTask( 'lint.js' ) - ); +--repos: comma separated list of repos to lint in addition to the repo from running` ); - grunt.registerTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)', - execTask( 'lint-all.js' ) - ); + registerForwardedTask( 'lint-all', 'lint all js files that are required to build this repository (for the specified brands)' ); - grunt.registerTask( 'generate-development-html', - 'Generates top-level SIM_en.html file based on the preloads in package.json.', - execTask( 'generate-development-html.js' ) - ); + registerForwardedTask( 'generate-development-html', + 'Generates top-level SIM_en.html file based on the preloads in package.json.' ); - grunt.registerTask( 'generate-test-html', + registerForwardedTask( 'generate-test-html', 'Generates top-level SIM-tests.html file based on the preloads in package.json. See https://github.com/phetsims/aqua/blob/main/doc/adding-unit-tests.md ' + 'for more information on automated testing. Usually you should ' + - 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.', - execTask( 'generate-test-html.js' ) - ); + 'set the "generatedUnitTests":true flag in the sim package.json and run `grunt update` instead of manually generating this.' ); - grunt.registerTask( 'generate-a11y-view-html', + registerForwardedTask( 'generate-a11y-view-html', 'Generates top-level SIM-a11y-view.html file used for visualizing accessible content. Usually you should ' + 'set the "phet.simFeatures.supportsInteractiveDescription":true flag in the sim package.json and run `grunt update` ' + - 'instead of manually generating this.', - execTask( 'generate-a11y-view.js' ) - ); + 'instead of manually generating this.' ); - grunt.registerTask( 'update', ` + registerForwardedTask( 'update', ` Updates the normal automatically-generated files for this repository. Includes: * runnables: generate-development-html and modulify * accessible runnables: generate-a11y-view-html * unit tests: generate-test-html * simulations: generateREADME() * phet-io simulations: generate overrides file if needed - * create the conglomerate string files for unbuilt mode, for this repo and its dependencies`, - execTask( 'update.js' ) - ); + * create the conglomerate string files for unbuilt mode, for this repo and its dependencies` ); // This is not run in grunt update because it affects dependencies and outputs files outside of the repo. - grunt.registerTask( 'generate-development-strings', + registerForwardedTask( 'generate-development-strings', 'To support locales=* in unbuilt mode, generate a conglomerate JSON file for each repo with translations in babel. Run on all repos via:\n' + '* for-each.sh perennial-alias/data/active-repos npm install\n' + - '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings', - execTask( 'generate-development-strings.js' ) - ); + '* for-each.sh perennial-alias/data/active-repos grunt generate-development-strings' ); - grunt.registerTask( 'published-README', - 'Generates README.md file for a published simulation.', - execTask( 'published-README.js' ) - ); + registerForwardedTask( 'published-README', + 'Generates README.md file for a published simulation.' ); - grunt.registerTask( 'unpublished-README', - 'Generates README.md file for an unpublished simulation.', - execTask( 'unpublished-README.js' ) - ); + registerForwardedTask( 'unpublished-README', + 'Generates README.md file for an unpublished simulation.' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? // AV would like a way to sort the imports, OK if it is a grunt script or node script. As long as there way to do it. @@ -171,58 +157,44 @@ // MK: Make an issue to make the sort by module part of the code style. Reformat the codebase by that style. // MK: All opposed? // MK: is working on it. - grunt.registerTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified', - execTask( 'sort-imports.js' ) - ); + registerForwardedTask( 'sort-imports', 'Sort the import statements for a single file (if --file={{FILE}} is provided), or does so for all JS files if not specified' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt // SR, AV, JB, MK, JG do not use it. We will check with @pixelzoom to see if it is OK to move to node. // MK: But it is nice having a central registry + pattern for "things we run in sim/common repos" - grunt.registerTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.', - execTask( 'commits-since.js' ) - ); + registerForwardedTask( 'commits-since', 'Shows commits since a specified date. Use --date= to specify the date.' ); // See reportMedia.js - grunt.registerTask( 'report-media', + registerForwardedTask( 'report-media', '(project-wide) Report on license.json files throughout all working copies. ' + 'Reports any media (such as images or sound) files that have any of the following problems:\n' + '(1) incompatible-license (resource license not approved)\n' + '(2) not-annotated (license.json missing or entry missing from license.json)\n' + - '(3) missing-file (entry in the license.json but not on the file system)', - execTask( 'report-media.js' ) - ); + '(3) missing-file (entry in the license.json but not on the file system)' ); // see reportThirdParty.js // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt - grunt.registerTask( 'report-third-party', + registerForwardedTask( 'report-third-party', 'Creates a report of third-party resources (code, images, sound, etc) used in the published PhET simulations by ' + 'reading the license information in published HTML files on the PhET website. This task must be run from main. ' + - 'After running this task, you must push sherpa/third-party-licenses.md.', - execTask( 'report-third-party.js' ) - ); + 'After running this task, you must push sherpa/third-party-licenses.md.' ); - grunt.registerTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo', - execTask( 'modulify.js' ) - ); + registerForwardedTask( 'modulify', 'Creates *.js modules for all images/strings/audio/etc in a repo' ); // Grunt task that determines created and last modified dates from git, and // updates copyright statements accordingly, see #403 - grunt.registerTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates', - execTask( 'update-copyright-dates.js' ) - ); + registerForwardedTask( 'update-copyright-dates', 'Update the copyright dates in JS source files based on Github dates' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt, or maybe just delete? // Dev meeting consensus: DELETE - grunt.registerTask( + registerForwardedTask( 'webpack-dev-server', `Runs a webpack server for a given list of simulations. --repos=REPOS for a comma-separated list of repos (defaults to current repo) --port=9000 to adjust the running port --devtool=string value for sourcemap generation specified at https://webpack.js.org/configuration/devtool or undefined for (none) - --chrome: open the sims in Chrome tabs (Mac)`, - execTask( 'webpack-dev-server.js' ) - ); + --chrome: open the sims in Chrome tabs (Mac)` ); - grunt.registerTask( + registerForwardedTask( 'generate-phet-io-api', 'Output the PhET-iO API as JSON to phet-io-sim-specific/api.\n' + 'Options\n:' + @@ -230,11 +202,9 @@ '--simList=... a file with a list of sims to compare (defaults to the sim in the current dir)\n' + '--stable - regenerate for all "stable sims" (see perennial/data/phet-io-api-stable/)\n' + '--temporary - outputs to the temporary directory\n' + - '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.', - execTask( 'generate-phet-io-api.js' ) - ); + '--transpile=false - skips the transpilation step. You can skip transpilation if a watch process is handling it.' ); - grunt.registerTask( + registerForwardedTask( 'compare-phet-io-api', 'Compares the phet-io-api against the reference version(s) if this sim\'s package.json marks compareDesignedAPIChanges. ' + 'This will by default compare designed changes only. Options:\n' + @@ -243,20 +213,14 @@ '--stable, generate the phet-io-apis for each phet-io sim considered to have a stable API (see perennial-alias/data/phet-io-api-stable)\n' + '--delta, by default a breaking-compatibility comparison is done, but --delta shows all changes\n' + '--temporary, compares API files in the temporary directory (otherwise compares to freshly generated APIs)\n' + - '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes', - execTask( 'compare-phet-io-api.js' ) - ); + '--compareBreakingAPIChanges - add this flag to compare breaking changes in addition to designed changes' ); // TODO: https://github.com/phetsims/chipper/issues/1461 probably does not need to be here in grunt. Does anyone use it? Search for docs in the code review checklist // Dev team consensus: move to node. Run like this: `node ../chipper/js/scripts/profile-file-size.js` // TODO: Add to code review checklist, see https://github.com/phetsims/chipper/issues/1461 - grunt.registerTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo', - execTask( 'profile-file-size.js' ) - ); + registerForwardedTask( 'profile-file-size', 'Profiles the file size of the built JS file for a given repo' ); - grunt.registerTask( 'test-grunt', 'Run tests for the Gruntfile', - execTask( 'test-grunt.js' ) - ); + registerForwardedTask( 'test-grunt', 'Run tests for the Gruntfile' ); /** * Creates grunt tasks that effectively get forwarded to perennial. It will execute a grunt process running from @@ -297,7 +261,7 @@ spawned.on( 'close', code => { if ( code !== 0 ) { - throw new Error( `perennial grunt ${argsString} failed with code ${code}` ); + throw new Error( `spawn: ${command} ${argsString} failed with code ${code}` ); } else { done(); Index: chipper/js/grunt/.eslintrc.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/chipper/js/grunt/.eslintrc.js b/chipper/js/grunt/.eslintrc.js --- a/chipper/js/grunt/.eslintrc.js (revision 79e88551b1bbdc778a5c4bf40e7f4070486b3cde) +++ b/chipper/js/grunt/.eslintrc.js (date 1726517748545) @@ -4,5 +4,31 @@ module.exports = { // Use all of the default rules from eslint file for node code. - extends: '../../../chipper/eslint/chipper_eslintrc.js' + extends: process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/eslint/chipper_eslintrc.js', + + parserOptions: { + sourceType: 'module' + }, + + overrides: [ { + files: [ '**/*.ts' ], + + parserOptions: { + + // Provide a tsconfig so that we can use rules that require type information. + // NOTE: Providing this slows down eslint substantially, see https://github.com/phetsims/chipper/issues/1114#issuecomment-1065927717 + + // IntelliJ runs this from chipper/js/grunt so the path is different than when running from chipper/, so we must normalize + // to support both IDE and command line + // for debugging here, you can put variables into the project then navigate to a file using this (like a *.ts file) + // and see the output in the bad path, or you can write to the file system. + project: [ process.cwd().substring( 0, process.cwd().lastIndexOf( 'chipper' ) + 'chipper'.length ) + '/tsconfig/all/tsconfig.json' ] + }, + + // disable rules @typescript-eslint/no-require-imports,@typescript-eslint/no-var-requires + rules: { + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/no-var-requires': 'off' + } + } ] }; \ No newline at end of file ```
samreid commented 11 hours ago

Patch for tsconfig and next steps:

```diff Subject: [PATCH] Fix module resolution and import jimp, see https://github.com/phetsims/chipper/issues/1459 --- Index: js/getStringModule.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/getStringModule.ts b/js/getStringModule.ts --- a/js/getStringModule.ts (revision ce419be8db96fdfa2883db184e96eba02b056900) +++ b/js/getStringModule.ts (date 1726592587961) @@ -41,6 +41,21 @@ } ); }; +process.env; +process.blarg; + +document.hello; +window.hello; +global.hello; + +global.process; +global.hello; + +window.location; + +const myDiv = document.createElement( 'div' ); +console.log( myDiv ); + const stringKeyToTandemName = ( key: string ) => { return key.replace( /(?:[-_\s]\w)/g, word => word[ 1 ].toUpperCase() ); }; Index: tsconfig-node.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig-node.json b/tsconfig-node.json new file mode 100644 --- /dev/null (date 1726592503627) +++ b/tsconfig-node.json (date 1726592503627) @@ -0,0 +1,31 @@ +{ + "extends": "./tsconfig-supercore.json", + "compilerOptions": { + // Treat files as modules even if it doesn't use import/export + "moduleDetection": "force", + // Ignore module structure + "module": "NodeNext", + // Allow JSON modules to be imported + "resolveJsonModule": true, + // Allow JS files to be imported from TS and vice versa + "allowJs": true, + // Use correct ESM import behavior + "esModuleInterop": true, + // Disallow features that require cross-file awareness + "isolatedModules": true, + "strict": true, + "moduleResolution": "NodeNext", + "target": "ESNext", + "lib": [ + "ESNext" + ] + } +} + +/* +, +"compilerOptions": { +"esModuleInterop": true, +"allowSyntheticDefaultImports": true, +"moduleResolution": "node" +}*/ Index: js/grunt/tasks/update.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/update.ts b/js/grunt/tasks/update.ts --- a/js/grunt/tasks/update.ts (revision ce419be8db96fdfa2883db184e96eba02b056900) +++ b/js/grunt/tasks/update.ts (date 1726592424359) @@ -14,6 +14,7 @@ import * as grunt from 'grunt'; import getRepo from './util/getRepo'; import * as fs from 'fs'; +import IntentionalAny from '../../../../phet-core/js/types/IntentionalAny.js'; const repo = getRepo(); Index: tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig.json b/tsconfig.json --- a/tsconfig.json (revision ce419be8db96fdfa2883db184e96eba02b056900) +++ b/tsconfig.json (date 1726593261728) @@ -6,9 +6,10 @@ "mipmaps/**/*", "sounds/**/*" ], - "compilerOptions": { - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "moduleResolution": "node" - } + "files": [ + "js/Gruntfile.ts" + ], + "exclude": [ + "js/grunt/**/*" + ] } \ No newline at end of file Index: js/grunt/tasks/clean.ts IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tasks/clean.ts b/js/grunt/tasks/clean.ts --- a/js/grunt/tasks/clean.ts (revision ce419be8db96fdfa2883db184e96eba02b056900) +++ b/js/grunt/tasks/clean.ts (date 1726592587969) @@ -6,8 +6,8 @@ * @author Sam Reid (PhET Interactive Simulations) */ -import getRepo from './util/getRepo'; import * as grunt from 'grunt'; +import getRepo from './util/getRepo'; const repo = getRepo(); const buildDirectory = `../${repo}/build`; @@ -16,4 +16,19 @@ if ( grunt.file.exists( buildDirectory ) ) { grunt.file.delete( buildDirectory ); } -grunt.file.mkdir( buildDirectory ); \ No newline at end of file +grunt.file.mkdir( buildDirectory ); + +process.env; +process.blarg; + +document.hello; +window.hello; +global.hello; + +global.process; +global.hello; + +window.location; + +const myDiv = document.createElement( 'div' ); +console.log( myDiv ); \ No newline at end of file Index: tsconfig-supercore.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig-supercore.json b/tsconfig-supercore.json new file mode 100644 --- /dev/null (date 1726592123623) +++ b/tsconfig-supercore.json (date 1726592123623) @@ -0,0 +1,76 @@ +/** + * Shared defaults for tsconfig files. + * @author Sam Reid (PhET Interactive Simulations) + */ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + "incremental": true, /* Enable incremental compilation */ + "target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */ + "module": "ES2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + "allowJs": true, /* Allow javascript files to be compiled. */ + "checkJs": false, /* Report errors in .js files. */ + "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": false, /* Generates corresponding '.map' file. */ + "outDir": "../chipper/dist/tsc/outDir", /* Redirect output structure to the directory. */ + "rootDir": "../", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + "composite": false, /* Enable project compilation (project references) */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + "noEmit": false, /* Emit outputs. */ + "emitDeclarationOnly": true, /* But not js output, because we use babel ourselves */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + // "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} \ No newline at end of file Index: tsconfig-core.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tsconfig-core.json b/tsconfig-core.json --- a/tsconfig-core.json (revision ce419be8db96fdfa2883db184e96eba02b056900) +++ b/tsconfig-core.json (date 1726592666014) @@ -3,75 +3,11 @@ * @author Sam Reid (PhET Interactive Simulations) */ { + "extends": "./tsconfig-supercore.json", "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Basic Options */ - "incremental": true, /* Enable incremental compilation */ - "target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */ - "module": "ES2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ - // "lib": [], /* Specify library files to be included in the compilation. */ - "allowJs": true, /* Allow javascript files to be compiled. */ - "checkJs": false, /* Report errors in .js files. */ - "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ - "declaration": true, /* Generates corresponding '.d.ts' file. */ - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - "sourceMap": false, /* Generates corresponding '.map' file. */ - "outDir": "../chipper/dist/tsc/outDir", /* Redirect output structure to the directory. */ - "rootDir": "../", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - "composite": false, /* Enable project compilation (project references) */ - // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - // "removeComments": true, /* Do not emit comments to output. */ - "noEmit": false, /* Emit outputs. */ - "emitDeclarationOnly": true, /* But not js output, because we use babel ourselves */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ - "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ - - /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - // "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - - /* Advanced Options */ - "skipLibCheck": true, /* Skip type checking of declaration files. */ - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + "lib": [ + "DOM" + ] }, "files": [ "phet-types.d.ts", Index: js/grunt/tsconfig.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/js/grunt/tsconfig.json b/js/grunt/tsconfig.json new file mode 100644 --- /dev/null (date 1726591845136) +++ b/js/grunt/tsconfig.json (date 1726591845136) @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig-node.json", + "include": [ + "**/*" + ] +} \ No newline at end of file
samreid commented 9 hours ago

After reverting the patch, I made minor updates until lint-everything and tsc all were passing. It seems we are in a good spot to merge this branch to main, then continue in a subsequent issue and a new branch.

samreid commented 9 hours ago

I merged the above commits to main and pushed. I described on slack for other developers to pull and npm update in chipper. I'll open a new issue + new branch for next steps.

samreid commented 4 hours ago

Everything completed on tracked in other issues. We now support TypeScript in chipper/js/grunt. But we would like to work on #1463 and #1463 before recommending broader usage to the team. Closing.