Skip to content

Commit

Permalink
Convert phet-build-script output to *.mjs, see #1272
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Aug 22, 2022
1 parent 47b6c79 commit 4f9ae71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions js/common/Transpiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class Transpiler {
static getTargetPath( filename ) {
const relativePath = path.relative( root, filename );
const suffix = relativePath.substring( relativePath.lastIndexOf( '.' ) );
return Transpiler.join( root, 'chipper', 'dist', 'js', ...relativePath.split( path.sep ) ).split( suffix ).join( '.js' );

// Note: When we upgrade to Node 16, this may no longer be necessary, see https://github.com/phetsims/chipper/issues/1272#issuecomment-1222574593
const extension = relativePath.includes( 'phet-build-script' ) ? '.mjs' : '.js';
return Transpiler.join( root, 'chipper', 'dist', 'js', ...relativePath.split( path.sep ) ).split( suffix ).join( extension );
}

/**
Expand Down Expand Up @@ -131,9 +134,14 @@ class Transpiler {
const tail = path.substring( start.length );

const correspondingFile = `../${tail}`;
const tsFile = correspondingFile.split( '.js' ).join( '.ts' );
const tsxFile = correspondingFile.split( '.js' ).join( '.tsx' );
if ( !fs.existsSync( correspondingFile ) && !fs.existsSync( tsFile ) && !fs.existsSync( tsxFile ) ) {
const jsTsFile = correspondingFile.split( '.js' ).join( '.ts' );
const jsTsxFile = correspondingFile.split( '.js' ).join( '.tsx' );
const mjsTsFile = correspondingFile.split( '.mjs' ).join( '.ts' );
const mjsTsxFile = correspondingFile.split( '.mjs' ).join( '.tsx' );
if ( !fs.existsSync( correspondingFile ) &&
!fs.existsSync( jsTsFile ) && !fs.existsSync( jsTsxFile ) &&
!fs.existsSync( mjsTsFile ) && !fs.existsSync( mjsTsxFile )
) {
fs.unlinkSync( path );
console.log( 'No parent source file for: ' + path + ', deleted.' );
}
Expand Down
2 changes: 1 addition & 1 deletion js/grunt/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports = function( grunt ) {
return () => {
const done = grunt.task.current.async();

const p = child_process.spawn( 'node', [ '../chipper/dist/js/chipper/js/phet-build-script/phet-build-script.js', ...args ], {
const p = child_process.spawn( 'node', [ '../chipper/dist/js/chipper/js/phet-build-script/phet-build-script.mjs', ...args ], {
cwd: process.cwd()
} );

Expand Down

0 comments on commit 4f9ae71

Please sign in to comment.