Skip to content

Commit

Permalink
chore: Upgrade Yarn to the latest version (4.6.0) and upgrade depende…
Browse files Browse the repository at this point in the history
…ncies
  • Loading branch information
hangxingliu committed Jan 1, 2025
1 parent d075c80 commit e52fcdd
Show file tree
Hide file tree
Showing 6 changed files with 5,776 additions and 3,611 deletions.
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# use proxy configuration from environment variables
httpProxy: "${http_proxy-}"
httpsProxy: "${https_proxy-}"

nodeLinker: node-modules
8 changes: 6 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
date: 2024-03-13
date: 2025-01-01
---
# Contributing

Expand Down Expand Up @@ -47,9 +47,13 @@ date: 2024-03-13

- [Git](https://git-scm.com/)
- [Node.js](https://nodejs.org/en/)
- [Yarn Classic](https://classic.yarnpkg.com/en/)
- [Yarn](https://yarnpkg.com/getting-started/install)
- [Visual Studio Code](https://code.visualstudio.com/)

> [!NOTE]
> 1. Only Node.js [LTS versions](https://nodejs.org/en/about/previous-releases) are supported
> 2. The classic yarn cannot be used in this project.
## References

- <https://code.visualstudio.com/api>
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = tseslint.config(eslint.configs.recommended, ...tseslint.configs
// https://github.com/typescript-eslint/typescript-eslint/issues/2621
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }],
"@typescript-eslint/no-require-imports": "off",
},
languageOptions: {
globals: {
Expand Down
35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"publisher": "hangxingliu",
"author": "hangxingliu",
"license": "MIT",
"packageManager": "[email protected]",
"engines": {
"vscode": "^1.64.0",
"node": "^16.9 || >=18.0"
Expand Down Expand Up @@ -216,31 +217,31 @@
]
},
"devDependencies": {
"@swc/cli": "^0.3.9",
"@swc/core": "^1.4.2",
"@types/node": "^20.9.3",
"@types/turndown": "^5.0.4",
"@swc/cli": "^0.5.2",
"@swc/core": "^1.10.4",
"@types/node": "^22.10.2",
"@types/turndown": "^5.0.5",
"@types/vscode": "^1.64.0",
"axios": "^1",
"axios": "^1.7.9",
"cheerio": "1.0.0-rc.12",
"copyfiles": "^2.4.1",
"escape-html": "^1.0.3",
"html-entities": "^2.5.2",
"https-proxy-agent": "^7",
"marked": "^12.0.1",
"rimraf": "^5",
"swc-loader": "^0.2.3",
"turndown": "^7.1.2",
"https-proxy-agent": "^7.0.6",
"marked": "^12.0.2",
"rimraf": "^6.0.1",
"swc-loader": "^0.2.6",
"turndown": "^7.2.0",
"turndown-plugin-gfm": "^1.0.2",
"typescript": "^5",
"webpack": "^5",
"webpack-cli": "^5"
"typescript": "^5.7.2",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1"
},
"optionalDependencies": {
"@eslint/js": "^9.1.1",
"@vscode/vsce": "^2.24.0",
"eslint": "^9.1.1",
"typescript-eslint": "^7.7.1"
"@eslint/js": "^9.17.0",
"@vscode/vsce": "^3.2.1",
"eslint": "^9.17.0",
"typescript-eslint": "^8.19.0"
},
"repository": {
"type": "git",
Expand Down
55 changes: 44 additions & 11 deletions scripts/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,33 @@
// template: run-cjs.js
// author: hangxingliu
// license: MIT
// version: 2024-03-12
// version: 2024-10-02
const { platform } = require("os");
const { existsSync } = require("fs");
const { resolve, basename, dirname } = require("path");
const { spawn, spawnSync } = require("child_process");
const runFromPackageScript = !!process.env.npm_execpath;
const runFromYarn = /yarn\/bin/.test(process.env.npm_execpath || "");
const isWin32 = platform() === "win32";
// yarn/bin: classical yarn (v1)
// /yarn: yarn v2
const runFromYarn = /(yarn\/bin|\/yarn$)/.test(process.env.npm_execpath || "");

/** @see https://stackoverflow.com/questions/14031763 */
const npmUA = process.env.npm_config_user_agent || "";
const isYarnV2 = /\byarn\/([2-9]\d*|1\d+)\./.test(npmUA);

const resetColor = "\x1b[0m";
/**
* @see https://stackoverflow.com/questions/14031763
* @type {Array<()=>any>}
*/
const cleanupCallbacks = [];
/** @param {number} [exitCode] */
function cleanup(exitCode) {
while (cleanupCallbacks.length > 0) cleanupCallbacks.pop()();
let callback = cleanupCallbacks.pop();
while (callback) {
callback();
callback = cleanupCallbacks.pop();
}
if (typeof exitCode === "number") process.exit(exitCode);
}
/** @param {() => void} callback */
Expand All @@ -46,7 +59,7 @@ function printExitStatus(bin, code, signal) {
}

/** @typedef {typeof process.env} SystemEnv */
/** @typedef {{ env?: SystemEnv; cwd?: string; shortName?: boolean }} ExecSyncOptions */
/** @typedef {{ env?: SystemEnv; cwd?: string; shortName?: boolean; showCmd?: boolean }} ExecSyncOptions */
/** @typedef {ExecSyncOptions & { silent?: boolean }} ExecOptions */

/**
Expand All @@ -69,10 +82,10 @@ function execSync(command, opts) {
env.PATH = prependNodeModulesBinIntoPath(process.cwd(), env.PATH);
}

console.error(`+ (sync) ${binName} ${args.join(" ")}`);
if (!opts || opts.showCmd !== false) console.error(`${resetColor}+ (sync) ${bin} ${args.join(" ")}`);
const ret = spawnSync(bin, args, { cwd, env, stdio: ["inherit", "inherit", "inherit"] });
if (ret.status !== 0) {
printExitStatus(bin, ret.status, ret.signal);
printExitStatus(binName, ret.status, ret.signal);
process.exit(ret.status || 1);
}
}
Expand Down Expand Up @@ -100,19 +113,19 @@ function exec(command, opts) {
env.PATH = prependNodeModulesBinIntoPath(process.cwd(), env.PATH);
}

console.error(`+ ${binName} ${args.join(" ")}`);
if (!opts || opts.showCmd !== false) console.error(`+ ${bin} ${args.join(" ")}`);
const child = spawn(bin, args, { cwd, env, stdio: [stdout, "inherit", "inherit"] });

/** @type {Promise<number|null>} */
const promise = new Promise((resolve, reject) => {
child.on("error", reject);
child.on("exit", (code, signal) => {
printExitStatus(bin, code, signal);
printExitStatus(binName, code, signal);
return resolve(code);
});
});
const kill = () => {
console.error(`killing ${bin} ...`);
console.error(`killing ${binName} ...`);
try {
child.kill();
} catch (error) {
Expand All @@ -124,6 +137,24 @@ function exec(command, opts) {
return { child, promise, kill };
}

/**
* Resolve a cli script with the latest yarn compatiable
* @param {string} defaultBinName
* @param {string} [requirePath]
* @returns {string[]}
*/
function resolveCmd(defaultBinName, requirePath) {
if (requirePath) {
try {
const scriptPath = require.resolve(requirePath);
return [process.execPath, scriptPath];
} catch (error) {
// noop
}
}
return [defaultBinName];
}

/**
* @param {string} baseDir
* @param {string} [envPATH]
Expand Down Expand Up @@ -180,7 +211,8 @@ async function runPackageScripts(args) {
}
if (scripts.length === 0) return;
const base = [runFromYarn ? "yarn" : "npm", "run", "--silent"];
if (runFromYarn) base.splice(1, 0, "--ignore-engines");
if (isYarnV2) base.pop(); // remove '--silent'
else if (runFromYarn) base.splice(1, 0, "--ignore-engines");
if (parallel) return Promise.all(scripts.map((script) => exec([...base, script]).promise));
for (const script of scripts) execSync([...base, script]);
return;
Expand All @@ -191,6 +223,7 @@ exports.exec = exec;
exports.execSync = execSync;
exports.isTrue = isTrue;
exports.run = runPackageScripts;
exports.resolveCmd = resolveCmd;
if (typeof require !== "undefined" && require.main === module) {
runPackageScripts(process.argv.slice(2)).catch((error) => {
console.error(typeof error === "string" ? `Error: ${error}` : error);
Expand Down
Loading

0 comments on commit e52fcdd

Please sign in to comment.