Skip to content

Commit

Permalink
Update imports, see #1459
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Sep 17, 2024
1 parent 7a1b7ff commit 42bf3d8
Show file tree
Hide file tree
Showing 32 changed files with 92 additions and 74 deletions.
4 changes: 2 additions & 2 deletions js/grunt/tasks/build-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* @author Sam Reid (PhET Interactive Simulations)
*/
const grunt = require( 'grunt' );
const getRepo = require( './util/getRepo' );
import * as grunt from 'grunt';
import getRepo from './util/getRepo';

const jimp = require( 'jimp' );
const generateThumbnails = require( '../generateThumbnails' );
Expand Down
10 changes: 5 additions & 5 deletions js/grunt/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const path = require( 'path' );
const fs = require( 'fs' );
const getPhetLibs = require( '../getPhetLibs' );
const phetTimingLog = require( '../../../../perennial-alias/js/common/phetTimingLog' );

const grunt = require( 'grunt' );
const getRepo = require( './util/getRepo' );
import * as grunt from 'grunt';
import getRepo from './util/getRepo';
const assert = require( 'assert' );
const Transpiler = require( '../../common/Transpiler' );
const getBrands = require( './util/getBrands' );
const getOption = require( './util/getOption' );
import getOption from './util/getOption';
const buildLocal = require( './util/buildLocal' );
import IntentionalAny from '../../../../phet-core/js/types/IntentionalAny.js';

const repo = getRepo();

Expand All @@ -51,7 +51,7 @@ const transpiler = new Transpiler( { silent: true } );

// Parse minification keys
const minifyKeys = Object.keys( minify.MINIFY_DEFAULTS );
const minifyOptions = {};
const minifyOptions: IntentionalAny = {};
minifyKeys.forEach( minifyKey => {
const option = getOption( `minify.${minifyKey}` );
if ( option === true || option === false ) {
Expand Down
4 changes: 2 additions & 2 deletions js/grunt/tasks/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* @author Sam Reid (PhET Interactive Simulations)
*/

const getRepo = require( './util/getRepo' );
const grunt = require( 'grunt' );
import getRepo from './util/getRepo';
import * as grunt from 'grunt';

const repo = getRepo();
const buildDirectory = `../${repo}/build`;
Expand Down
22 changes: 11 additions & 11 deletions js/grunt/tasks/commits-since.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );

/**
* Shows commits since a specified date. Use --date=<date> to specify the date.
*
* @author Sam Reid (PhET Interactive Simulations)
*/

// 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"
// 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"

import getRepo from './util/getRepo';

const repo = getRepo();
const getOption = require( './util/getOption' );
const commitsSince = require( '../commitsSince' );
const assert = require( 'assert' );
import getOption from './util/getOption';

const repo = getRepo();
const dateString = getOption( 'date' );
assert( dateString, 'missing required option: --date={{DATE}}' );

const commitsSince = require( '../commitsSince' );
const assert = require( 'assert' );

await commitsSince( repo, dateString );
( async () => {
await commitsSince( repo, dateString );
} )();
17 changes: 9 additions & 8 deletions js/grunt/tasks/compare-phet-io-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );

/**
*
* Compares the phet-io-api against the reference version(s) if this sim's package.json marks compareDesignedAPIChanges.
Expand All @@ -15,22 +13,25 @@ const getRepo = require( './util/getRepo' );
*
* @author Sam Reid (PhET Interactive Simulations)
*/
const grunt = require( 'grunt' );
import * as grunt from 'grunt';
import IntentionalAny from '../../../../phet-core/js/types/IntentionalAny.js';
import getRepo from './util/getRepo';

const getSimList = require( '../../common/getSimList' );
const generatePhetioMacroAPI = require( '../../phet-io/generatePhetioMacroAPI' );
const fs = require( 'fs' );
const getOption = require( './util/getOption' );
import getOption from './util/getOption';

const repo = getRepo();
const sims = getSimList().length === 0 ? [ repo ] : getSimList();
const sims: string[] = getSimList().length === 0 ? [ repo ] : getSimList();
const temporary = getOption( 'temporary' );
let proposedAPIs = null;
let proposedAPIs: Record<string, string> | null = null;

( async () => {
if ( temporary ) {
proposedAPIs = {};
sims.forEach( sim => {
proposedAPIs[ sim ] = JSON.parse( fs.readFileSync( `../phet-io-sim-specific/repos/${repo}/${repo}-phet-io-api-temporary.json`, 'utf8' ) );
proposedAPIs![ sim ] = JSON.parse( fs.readFileSync( `../phet-io-sim-specific/repos/${repo}/${repo}-phet-io-api-temporary.json`, 'utf8' ) );
} );
}
else {
Expand All @@ -46,7 +47,7 @@ let proposedAPIs = null;
}

// Don't add to options object if values are `undefined` (as _.extend will keep those entries and not mix in defaults
const options = {};
const options: IntentionalAny = {};
if ( getOption( 'delta' ) ) {
options.delta = getOption( 'delta' );
}
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/generate-a11y-view-html.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const generateA11yViewHTML = require( '../generateA11yViewHTML' );

/**
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/generate-development-html.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const generateDevelopmentHTML = require( '../generateDevelopmentHTML' );

/**
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/generate-development-strings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const generateDevelopmentStrings = require( '../generateDevelopmentStrings' );
const fs = require( 'fs' );

Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/generate-phet-io-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';

/**
* Output the PhET-iO API as JSON to phet-io-sim-specific/api.
Expand All @@ -19,9 +19,9 @@ const formatPhetioAPI = require( '../../phet-io/formatPhetioAPI' );
const getSimList = require( '../../common/getSimList' );
const generatePhetioMacroAPI = require( '../../phet-io/generatePhetioMacroAPI' );
const fs = require( 'fs' );
const getOption = require( './util/getOption' );
import getOption from './util/getOption';

const sims = getSimList().length === 0 ? [ repo ] : getSimList();
const sims: string[] = getSimList().length === 0 ? [ repo ] : getSimList();

// Ideally transpilation would be a no-op if the watch process is running. However, it can take 2+ seconds on
// macOS to check all files, and sometimes much longer (50+ seconds) if the cache mechanism is failing.
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/generate-test-html.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const generateTestHTML = require( '../generateTestHTML' );

/**
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/generate-used-strings-file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const getPhetLibs = require( '../getPhetLibs' );
const fs = require( 'fs' );
const webpackBuild = require( '../webpackBuild' );
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/lint-all.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const getBrands = require( './util/getBrands' );
const assert = require( 'assert' );
const grunt = require( 'grunt' );
import * as grunt from 'grunt';
const lint = require( '../lint' );

/**
Expand All @@ -14,7 +14,7 @@ const lint = require( '../lint' );

const repo = getRepo();

const getOption = require( './util/getOption' );
import getOption from './util/getOption';
const buildLocal = require( './util/buildLocal' );

// --disable-eslint-cache disables the cache, useful for developing rules
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
*
* @author Sam Reid (PhET Interactive Simulations)
*/
const grunt = require( 'grunt' );
const getRepo = require( './util/getRepo' );
import * as grunt from 'grunt';
import getRepo from './util/getRepo';
const lint = require( '../lint' );
const getOption = require( './util/getOption' );
import getOption from './util/getOption';

const repo = getRepo();

Expand Down
4 changes: 2 additions & 2 deletions js/grunt/tasks/modulify.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2024, University of Colorado Boulder
const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const modulify = require( '../modulify' );
const generateDevelopmentStrings = require( '../generateDevelopmentStrings' );
const fs = require( 'fs' );
import * as fs from 'fs';

/**
* Creates *.js modules for all images/strings/audio/etc in a repo
Expand Down
4 changes: 4 additions & 0 deletions js/grunt/tasks/output-js-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*
* @author Sam Reid (PhET Interactive Simulations)
*/
// Import something to trigger imports mode. TODO https://github.com/phetsims/chipper/issues/1459 a better way?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import IntentionalAny from '../../../../phet-core/js/types/IntentionalAny.js';

const Transpiler = require( '../../common/Transpiler' );
const transpiler = new Transpiler( { silent: true } );

Expand Down
3 changes: 2 additions & 1 deletion js/grunt/tasks/output-js-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* @author Sam Reid (PhET Interactive Simulations)
*/
const Transpiler = require( '../../common/Transpiler' );
const getOption = require( './util/getOption' );
import getOption from './util/getOption';

const transpiler = new Transpiler( { silent: true } );

const repos = getOption( 'repos' );
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/output-js.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';

/**
* Outputs JS just for the specified repo
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/profile-file-size.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';

/**
* Profiles the file size of the built JS file for a given repo
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/published-README.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';

/**
* Generates README.md file for a published simulation.
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/report-media.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';

/**
* (project-wide) Report on license.json files throughout all working copies.
Expand Down
6 changes: 3 additions & 3 deletions js/grunt/tasks/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// MK: All opposed?
// MK: is working on it.

const getRepo = require( './util/getRepo' );
const grunt = require( 'grunt' );
const getOption = require( './util/getOption' );
import getRepo from './util/getRepo';
import * as grunt from 'grunt';
import getOption from './util/getOption';
const sortImports = require( '../sortImports' );

const repo = getRepo();
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/test-grunt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Sam Reid (PhET Interactive Simulations)
*/

const getOption = require( './util/getOption' );
import getOption from './util/getOption';

// grunt test-grunt --brands=a,b,c --lint=false --noTSC
const brands = getOption( 'brands' );
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/unpublished-README.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';

/**
* Generates README.md file for an unpublished simulation.
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/update-copyright-dates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );
import getRepo from './util/getRepo';
const updateCopyrightDates = require( '../updateCopyrightDates' );

/**
Expand Down
10 changes: 5 additions & 5 deletions js/grunt/tasks/update.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2024, University of Colorado Boulder

const getRepo = require( './util/getRepo' );

/**
* Updates the normal automatically-generated files for this repository. Includes:
* * runnables: generate-development-html and modulify
Expand All @@ -13,13 +11,15 @@ const getRepo = require( './util/getRepo' );
*
* @author Sam Reid (PhET Interactive Simulations)
*/
const grunt = require( 'grunt' );
import * as grunt from 'grunt';
import getRepo from './util/getRepo';
import * as fs from 'fs';

const repo = getRepo();

const packageObject = grunt.file.readJSON( `../${repo}/package.json` );

const generateREADME = require( '../generateREADME' );
const fs = require( 'fs' );
const _ = require( 'lodash' );

// support repos that don't have a phet object
Expand Down Expand Up @@ -65,7 +65,7 @@ else {
grunt.file.write( 'package.json', JSON.stringify( packageObject, null, 2 ) );
}
}
catch( e ) {
catch( e: IntentionalAny ) {
if ( !e.message.includes( 'no such file or directory' ) ) {
throw e;
}
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/tasks/util/buildLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Sam Reid (PhET Interactive Simulations)
*/

const grunt = require( 'grunt' );
import * as grunt from 'grunt';

let buildLocal;
try {
Expand Down
Loading

0 comments on commit 42bf3d8

Please sign in to comment.