Unverified 提交 5ccd4d0a authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Migrate npm-scripts.js to npm-scripts.mjs (ES Module) (#1093)

上级 ad298bf9
...@@ -50,7 +50,7 @@ jobs: ...@@ -50,7 +50,7 @@ jobs:
with: with:
node-version: ${{ matrix.node }} 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 ci --ignore-scripts --omit=dev
- run: npm run worker:build - run: npm run worker:build
# Publish prebuild binaries on tag. # Publish prebuild binaries on tag.
......
...@@ -55,7 +55,7 @@ jobs: ...@@ -55,7 +55,7 @@ jobs:
with: with:
node-version: ${{ matrix.node }} 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 ci --ignore-scripts --omit=dev
- run: npm run install-clang-tools - run: npm run install-clang-tools
# TODO: Maybe fix this one day. # TODO: Maybe fix this one day.
......
# Changelog # Changelog
### Next
Migrate `npm-scripts.js` to `npm-scripts.mjs` (ES Module) ([PR #1093](https://github.com/versatica/mediasoup/pull/1093)).
### 3.12.2 ### 3.12.2
* CI: Use `ubuntu-20.04` to build mediasoup-worker prebuilt on Linux ([PR #1092](https://github.com/versatica/mediasoup/pull/1092)). * CI: Use `ubuntu-20.04` to build mediasoup-worker prebuilt on Linux ([PR #1092](https://github.com/versatica/mediasoup/pull/1092)).
......
const process = require('process'); import process from 'process';
const os = require('os'); import os from 'os';
const fs = require('fs'); import fs from 'fs';
const { execSync, spawnSync } = require('child_process'); import { execSync, spawnSync } from 'child_process';
const fetch = require('node-fetch'); import fetch from 'node-fetch';
const tar = require('tar'); import tar from 'tar';
const PKG = JSON.parse(fs.readFileSync('./package.json').toString()); const PKG = JSON.parse(fs.readFileSync('./package.json').toString());
const IS_FREEBSD = os.platform() === 'freebsd'; const IS_FREEBSD = os.platform() === 'freebsd';
...@@ -98,8 +98,8 @@ async function run() ...@@ -98,8 +98,8 @@ async function run()
case 'typescript:watch': case 'typescript:watch':
{ {
// NOTE: Load dep here since it's a devDependency. // NOTE: Load dep on demand since it's a devDependency.
const { TscWatchClient } = require('tsc-watch/client'); const { TscWatchClient } = await import('tsc-watch/client.js');
const watch = new TscWatchClient(); const watch = new TscWatchClient();
...@@ -200,8 +200,8 @@ async function run() ...@@ -200,8 +200,8 @@ async function run()
try try
{ {
octokit = getOctokit(); octokit = await getOctokit();
versionChanges = getVersionChanges(); versionChanges = await getVersionChanges();
} }
catch (error) catch (error)
{ {
...@@ -357,7 +357,7 @@ function lintNode() ...@@ -357,7 +357,7 @@ function lintNode()
{ {
logInfo('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() function lintWorker()
...@@ -599,7 +599,7 @@ async function uploadMacArmPrebuiltWorker() ...@@ -599,7 +599,7 @@ async function uploadMacArmPrebuiltWorker()
return; return;
} }
const octokit = getOctokit(); const octokit = await getOctokit();
logInfo('uploadMacArmPrebuiltWorker() | getting release info'); logInfo('uploadMacArmPrebuiltWorker() | getting release info');
...@@ -623,15 +623,15 @@ async function uploadMacArmPrebuiltWorker() ...@@ -623,15 +623,15 @@ async function uploadMacArmPrebuiltWorker()
}); });
} }
function getOctokit() async function getOctokit()
{ {
if (!process.env.GITHUB_TOKEN) if (!process.env.GITHUB_TOKEN)
{ {
throw new Error('missing GITHUB_TOKEN environment variable'); throw new Error('missing GITHUB_TOKEN environment variable');
} }
// NOTE: Load dep here since it's a devDependency. // NOTE: Load dep on demand since it's a devDependency.
const { Octokit } = require('@octokit/rest'); const { Octokit } = await import('@octokit/rest');
const octokit = new Octokit( const octokit = new Octokit(
{ {
...@@ -641,12 +641,12 @@ function getOctokit() ...@@ -641,12 +641,12 @@ function getOctokit()
return octokit; return octokit;
} }
function getVersionChanges() async function getVersionChanges()
{ {
logInfo('getVersionChanges()'); logInfo('getVersionChanges()');
// NOTE: Load dep here since it's a devDependency. // NOTE: Load dep on demand since it's a devDependency.
const marked = require('marked'); const marked = await import('marked');
const changelog = fs.readFileSync('./CHANGELOG.md').toString(); const changelog = fs.readFileSync('./CHANGELOG.md').toString();
const entries = marked.lexer(changelog); const entries = marked.lexer(changelog);
...@@ -692,19 +692,19 @@ function executeCmd(command, exitOnError = true) ...@@ -692,19 +692,19 @@ function executeCmd(command, exitOnError = true)
function logInfo(message) function logInfo(message)
{ {
// eslint-disable-next-line no-console // 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) function logWarn(message)
{ {
// eslint-disable-next-line no-console // 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) function logError(message)
{ {
// eslint-disable-next-line no-console // 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() function exitWithError()
......
差异被折叠。
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
"worker/Makefile", "worker/Makefile",
"worker/meson.build", "worker/meson.build",
"worker/meson_options.txt", "worker/meson_options.txt",
"npm-scripts.js" "npm-scripts.mjs"
], ],
"keywords": [ "keywords": [
"webrtc", "webrtc",
...@@ -48,25 +48,25 @@ ...@@ -48,25 +48,25 @@
"node": ">=16" "node": ">=16"
}, },
"scripts": { "scripts": {
"prepare": "node npm-scripts.js prepare", "prepare": "node npm-scripts.mjs prepare",
"postinstall": "node npm-scripts.js postinstall", "postinstall": "node npm-scripts.mjs postinstall",
"typescript:build": "node npm-scripts.js typescript:build", "typescript:build": "node npm-scripts.mjs typescript:build",
"typescript:watch": "node npm-scripts.js typescript:watch", "typescript:watch": "node npm-scripts.mjs typescript:watch",
"worker:build": "node npm-scripts.js worker:build", "worker:build": "node npm-scripts.mjs worker:build",
"worker:prebuild": "node npm-scripts.js worker:prebuild", "worker:prebuild": "node npm-scripts.mjs worker:prebuild",
"lint": "npm run lint:node && npm run lint:worker", "lint": "npm run lint:node && npm run lint:worker",
"lint:node": "node npm-scripts.js lint:node", "lint:node": "node npm-scripts.mjs lint:node",
"lint:worker": "node npm-scripts.js lint:worker", "lint:worker": "node npm-scripts.mjs lint:worker",
"format:worker": "node npm-scripts.js format:worker", "format:worker": "node npm-scripts.mjs format:worker",
"test": "npm run test:node && npm run test:worker", "test": "npm run test:node && npm run test:worker",
"test:node": "node npm-scripts.js test:node", "test:node": "node npm-scripts.mjs test:node",
"test:worker": "node npm-scripts.js test:worker", "test:worker": "node npm-scripts.mjs test:worker",
"coverage:node": "node npm-scripts.js coverage:node", "coverage:node": "node npm-scripts.mjs coverage:node",
"install-deps:node": "node npm-scripts.js install-deps:node", "install-deps:node": "node npm-scripts.mjs install-deps:node",
"install-clang-tools": "node npm-scripts.js install-clang-tools", "install-clang-tools": "node npm-scripts.mjs install-clang-tools",
"release:check": "node npm-scripts.js release:check", "release:check": "node npm-scripts.mjs release:check",
"release": "node npm-scripts.js release", "release": "node npm-scripts.mjs release",
"release:upload-mac-arm-prebuilt-worker": "node npm-scripts.js release:upload-mac-arm-prebuilt-worker" "release:upload-mac-arm-prebuilt-worker": "node npm-scripts.mjs release:upload-mac-arm-prebuilt-worker"
}, },
"jest": { "jest": {
"verbose": true, "verbose": true,
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
"dependencies": { "dependencies": {
"debug": "^4.3.4", "debug": "^4.3.4",
"h264-profile-level-id": "^1.0.1", "h264-profile-level-id": "^1.0.1",
"node-fetch": "^2.6.11", "node-fetch": "^3.3.1",
"supports-color": "^9.3.1", "supports-color": "^9.3.1",
"tar": "^6.1.15", "tar": "^6.1.15",
"uuid": "^9.0.0" "uuid": "^9.0.0"
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
"@octokit/rest": "^19.0.11", "@octokit/rest": "^19.0.11",
"@types/debug": "^4.1.8", "@types/debug": "^4.1.8",
"@types/jest": "^29.5.1", "@types/jest": "^29.5.1",
"@types/node": "^18.15.11", "@types/node": "^20.2.5",
"@types/uuid": "^9.0.1", "@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.59.7", "@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7", "@typescript-eslint/parser": "^5.59.7",
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论