Skip to content

Commit

Permalink
ESM/commonjs: parallel attempt (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Jul 3, 2023
1 parent 2a0b3d6 commit 8bb89bc
Show file tree
Hide file tree
Showing 5 changed files with 854 additions and 234 deletions.
28 changes: 17 additions & 11 deletions npm-scripts.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import process from 'process';
import path from 'path';
import os from 'os';
import fs from 'fs';
import { execSync } from 'child_process';
Expand Down Expand Up @@ -43,15 +44,9 @@ async function run()

case 'typescript:watch':
{
// NOTE: Load dep on demand since it's a devDependency.
const { TscWatchClient } = await import('tsc-watch/client.js');

const watch = new TscWatchClient();

deleteLib();

watch.on('success', replaceVersion);
watch.start('--pretty');
// NOTE: We need to enable tsc emit so it writes node/lib.
executeCmd('tsc --noEmit false --watch');

break;
}
Expand Down Expand Up @@ -122,14 +117,24 @@ function replaceVersion()
{
logInfo('replaceVersion()');

const files = [ 'lib/index.js', 'lib/index.d.ts' ];
const files = fs.readdirSync('lib',
{
withFileTypes : true,
recursive : true
});

for (const file of files)
{
const text = fs.readFileSync(file, { encoding: 'utf8' });
if (!file.isFile())
{
continue;
}

const filePath = path.join('lib', file.name);
const text = fs.readFileSync(filePath, { encoding: 'utf8' });
const result = text.replace(/__MEDIASOUP_CLIENT_VERSION__/g, PKG.version);

fs.writeFileSync(file, result, { encoding: 'utf8' });
fs.writeFileSync(filePath, result, { encoding: 'utf8' });
}
}

Expand Down Expand Up @@ -164,6 +169,7 @@ function buildTypescript(force = false)

deleteLib();
executeCmd('tsc');
executeCmd('rollup --config');
}

function lint()
Expand Down

0 comments on commit 8bb89bc

Please sign in to comment.