Skip to content

Commit

Permalink
Migrate npm-scripts.js to npm-scripts.mjs (ES Module) (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed May 29, 2023
1 parent ad298bf commit 5ccd4d0
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mediasoup-worker-prebuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
with:
node-version: ${{ matrix.node }}

# We need to install some NPM production deps for npm-scripts.js to work.
# We need to install some NPM production deps for npm-scripts.mjs to work.
- run: npm ci --ignore-scripts --omit=dev
- run: npm run worker:build
# Publish prebuild binaries on tag.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mediasoup-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
node-version: ${{ matrix.node }}

# We need to install some NPM production deps for npm-scripts.js to work.
# We need to install some NPM production deps for npm-scripts.mjs to work.
- run: npm ci --ignore-scripts --omit=dev
- run: npm run install-clang-tools
# TODO: Maybe fix this one day.
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


### Next

Migrate `npm-scripts.js` to `npm-scripts.mjs` (ES Module) ([PR #1093](https://github.com/versatica/mediasoup/pull/1093)).


### 3.12.2

* CI: Use `ubuntu-20.04` to build mediasoup-worker prebuilt on Linux ([PR #1092](https://github.com/versatica/mediasoup/pull/1092)).
Expand Down
42 changes: 21 additions & 21 deletions npm-scripts.js → npm-scripts.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const process = require('process');
const os = require('os');
const fs = require('fs');
const { execSync, spawnSync } = require('child_process');
const fetch = require('node-fetch');
const tar = require('tar');
import process from 'process';
import os from 'os';
import fs from 'fs';
import { execSync, spawnSync } from 'child_process';
import fetch from 'node-fetch';
import tar from 'tar';

const PKG = JSON.parse(fs.readFileSync('./package.json').toString());
const IS_FREEBSD = os.platform() === 'freebsd';
Expand Down Expand Up @@ -98,8 +98,8 @@ async function run()

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

const watch = new TscWatchClient();

Expand Down Expand Up @@ -200,8 +200,8 @@ async function run()

try
{
octokit = getOctokit();
versionChanges = getVersionChanges();
octokit = await getOctokit();
versionChanges = await getVersionChanges();
}
catch (error)
{
Expand Down Expand Up @@ -357,7 +357,7 @@ function lintNode()
{
logInfo('lintNode()');

executeCmd('eslint -c node/.eslintrc.js --max-warnings 0 node/src node/.eslintrc.js npm-scripts.js worker/scripts/gulpfile.js');
executeCmd('eslint -c node/.eslintrc.js --max-warnings 0 node/src node/.eslintrc.js npm-scripts.mjs worker/scripts/gulpfile.js');
}

function lintWorker()
Expand Down Expand Up @@ -599,7 +599,7 @@ async function uploadMacArmPrebuiltWorker()
return;
}

const octokit = getOctokit();
const octokit = await getOctokit();

logInfo('uploadMacArmPrebuiltWorker() | getting release info');

Expand All @@ -623,15 +623,15 @@ async function uploadMacArmPrebuiltWorker()
});
}

function getOctokit()
async function getOctokit()
{
if (!process.env.GITHUB_TOKEN)
{
throw new Error('missing GITHUB_TOKEN environment variable');
}

// NOTE: Load dep here since it's a devDependency.
const { Octokit } = require('@octokit/rest');
// NOTE: Load dep on demand since it's a devDependency.
const { Octokit } = await import('@octokit/rest');

const octokit = new Octokit(
{
Expand All @@ -641,12 +641,12 @@ function getOctokit()
return octokit;
}

function getVersionChanges()
async function getVersionChanges()
{
logInfo('getVersionChanges()');

// NOTE: Load dep here since it's a devDependency.
const marked = require('marked');
// NOTE: Load dep on demand since it's a devDependency.
const marked = await import('marked');

const changelog = fs.readFileSync('./CHANGELOG.md').toString();
const entries = marked.lexer(changelog);
Expand Down Expand Up @@ -692,19 +692,19 @@ function executeCmd(command, exitOnError = true)
function logInfo(message)
{
// eslint-disable-next-line no-console
console.log(`npm-scripts.js \x1b[36m[INFO] [${task}]\x1b\[0m`, message);
console.log(`npm-scripts \x1b[36m[INFO] [${task}]\x1b\[0m`, message);
}

function logWarn(message)
{
// eslint-disable-next-line no-console
console.warn(`npm-scripts.js \x1b[33m[WARN] [${task}]\x1b\[0m`, message);
console.warn(`npm-scripts \x1b[33m[WARN] [${task}]\x1b\[0m`, message);
}

function logError(message)
{
// eslint-disable-next-line no-console
console.error(`npm-scripts.js \x1b[31m[ERROR] [${task}]\x1b\[0m`, message);
console.error(`npm-scripts \x1b[31m[ERROR] [${task}]\x1b\[0m`, message);
}

function exitWithError()
Expand Down

0 comments on commit 5ccd4d0

Please sign in to comment.