From 6b4c78bb23d439be591d30832a3e399d99019616 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 24 Jun 2025 21:47:34 +0900 Subject: [PATCH 1/2] Upgrade yargs to v18 --- babel.config.js | 1 + jest.config.js | 6 + package-lock.json | 303 +++++++++++++++++++++++++++-------- package.json | 5 +- src/marp-cli.ts | 4 +- src/utils/__mocks__/yargs.ts | 6 - src/utils/yargs.ts | 10 +- test/marp-cli.ts | 1 - 8 files changed, 255 insertions(+), 81 deletions(-) delete mode 100644 src/utils/__mocks__/yargs.ts diff --git a/babel.config.js b/babel.config.js index e8d0b9e8..08270a0c 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,4 +1,5 @@ // This setting is used only to transform ESM while running Jest. module.exports = { presets: [['@babel/env', { targets: { node: 'current' } }]], + plugins: [['babel-plugin-transform-import-meta', { module: 'ES6' }]], } diff --git a/jest.config.js b/jest.config.js index ed926065..d982c75e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,7 +8,9 @@ const esModules = [ 'array-union', 'chalk', 'chrome-launcher', + 'cliui', 'find-up', + 'get-east-asian-width', 'globby', 'import-meta-resolve', 'is-docker', @@ -26,7 +28,9 @@ const esModules = [ 'pptxgenjs', 'slash', 'strip-ansi', + 'string-width', 'unicorn-magic', + 'yargs', 'yocto-queue', ] @@ -41,6 +45,8 @@ module.exports = { transform: { ...jsWithBabel.transform, '_configs[/\\\\].+\\.mjs$': 'babel-jest', + [`[/\\\\]node_modules[/\\\\](?:${esModules.join('|')})[/\\\\].+\\.mjs$`]: + 'babel-jest', '\\.s?css$': '/test/_transformers/css.js', '\\.png$': '/test/_transformers/png.js', '\\.pug$': '/test/_transformers/pug.js', diff --git a/package-lock.json b/package-lock.json index 69955001..c8383f10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "serve-index": "^1.9.1", "tmp": "^0.2.3", "ws": "^8.18.2", - "yargs": "^17.7.2" + "yargs": "^18.0.0" }, "bin": { "marp": "marp-cli.js" @@ -48,6 +48,7 @@ "@types/yargs": "^17.0.33", "@yao-pkg/pkg": "^6.5.1", "autoprefixer": "^10.4.21", + "babel-plugin-transform-import-meta": "^2.3.3", "bespoke": "bespokejs/bespoke", "chalk": "^5.4.1", "cheerio": "^1.1.0", @@ -3852,6 +3853,44 @@ "node": ">=18" } }, + "node_modules/@puppeteer/browsers/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@puppeteer/browsers/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@puppeteer/browsers/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@puppeteer/browsers/node_modules/semver": { "version": "7.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", @@ -3864,6 +3903,18 @@ "node": ">=10" } }, + "node_modules/@puppeteer/browsers/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/@puppeteer/browsers/node_modules/tar-fs": { "version": "3.0.9", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.9.tgz", @@ -3878,6 +3929,41 @@ "bare-path": "^3.0.0" } }, + "node_modules/@puppeteer/browsers/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/@puppeteer/browsers/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "license": "MIT", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@rollup/plugin-alias": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-alias/-/plugin-alias-5.1.1.tgz", @@ -5617,7 +5703,6 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -5630,7 +5715,6 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -5935,6 +6019,20 @@ "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/babel-plugin-transform-import-meta": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-import-meta/-/babel-plugin-transform-import-meta-2.3.3.tgz", + "integrity": "sha512-bbh30qz1m6ZU1ybJoNOhA2zaDvmeXMnGNBMVMDOJ1Fni4+wMBoy/j7MTRVmqAUCIcy54/rEnr9VEBsfcgbpm3Q==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@babel/template": "^7.25.9", + "tslib": "^2.8.1" + }, + "peerDependencies": { + "@babel/core": "^7.10.0" + } + }, "node_modules/babel-preset-current-node-syntax": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz", @@ -6680,70 +6778,40 @@ } }, "node_modules/cliui": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", - "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-9.0.1.tgz", + "integrity": "sha512-k7ndgKhwoQveBL+/1tqGJYNz097I7WOvwbmmU2AR5+magtbjPWQTS1C5vzGkBC8Ym8UWRzfKUzUUqFLypY4Q+w==", "license": "ISC", "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.1", - "wrap-ansi": "^7.0.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/cliui/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/cliui/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" + "string-width": "^7.2.0", + "strip-ansi": "^7.1.0", + "wrap-ansi": "^9.0.0" }, "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "node": ">=20" } }, - "node_modules/cliui/node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "license": "MIT", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } + "node_modules/cliui/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", + "license": "MIT" }, - "node_modules/cliui/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "node_modules/cliui/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", "license": "MIT", "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" }, "engines": { - "node": ">=10" + "node": ">=18" }, "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/co": { @@ -9035,7 +9103,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.3.0.tgz", "integrity": "sha512-vpeMIQKxczTD/0s2CdEWHcb0eeJe6TFjxb+J5xgX7hScxqrGuyjmv4c1D4A/gelKfyox0gJJwIHF+fLjeaM8kQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -10416,6 +10483,16 @@ } } }, + "node_modules/jest-cli/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/jest-cli/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -10449,6 +10526,71 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/jest-cli/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/jest-cli/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/jest-cli/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/jest-cli/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/jest-config": { "version": "30.0.2", "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-30.0.2.tgz", @@ -16934,7 +17076,6 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^6.0.1" @@ -18445,7 +18586,6 @@ "version": "9.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz", "integrity": "sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^6.2.1", @@ -18521,14 +18661,12 @@ "version": "10.4.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", - "dev": true, "license": "MIT" }, "node_modules/wrap-ansi/node_modules/string-width": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", - "dev": true, "license": "MIT", "dependencies": { "emoji-regex": "^10.3.0", @@ -18682,21 +18820,20 @@ } }, "node_modules/yargs": { - "version": "17.7.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", - "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-18.0.0.tgz", + "integrity": "sha512-4UEqdc2RYGHZc7Doyqkrqiln3p9X2DZVxaGbwhn2pi7MrRagKaOcIKe8L3OxYcbhXLgLFUS3zAYuQjKBQgmuNg==", "license": "MIT", "dependencies": { - "cliui": "^8.0.1", + "cliui": "^9.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.3", + "string-width": "^7.2.0", "y18n": "^5.0.5", - "yargs-parser": "^21.1.1" + "yargs-parser": "^22.0.0" }, "engines": { - "node": ">=12" + "node": "^20.19.0 || ^22.12.0 || >=23" } }, "node_modules/yargs-parser": { @@ -18708,6 +18845,38 @@ "node": ">=12" } }, + "node_modules/yargs/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", + "license": "MIT" + }, + "node_modules/yargs/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "license": "MIT", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/yargs/node_modules/yargs-parser": { + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-22.0.0.tgz", + "integrity": "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==", + "license": "ISC", + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=23" + } + }, "node_modules/yauzl": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-3.2.0.tgz", diff --git a/package.json b/package.json index 82a44e51..ae342d9c 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "@types/yargs": "^17.0.33", "@yao-pkg/pkg": "^6.5.1", "autoprefixer": "^10.4.21", + "babel-plugin-transform-import-meta": "^2.3.3", "bespoke": "bespokejs/bespoke", "chalk": "^5.4.1", "cheerio": "^1.1.0", @@ -148,6 +149,7 @@ "vhtml": "^2.2.0", "which": "^4.0.0", "wrap-ansi": "^9.0.0", + "yargs": "^18.0.0", "yauzl": "^3.2.0", "zip-stream": "^7.0.2" }, @@ -159,8 +161,7 @@ "puppeteer-core": "^24.10.0", "serve-index": "^1.9.1", "tmp": "^0.2.3", - "ws": "^8.18.2", - "yargs": "^17.7.2" + "ws": "^8.18.2" }, "publishConfig": { "access": "public" diff --git a/src/marp-cli.ts b/src/marp-cli.ts index 4f080841..ef1fe4e9 100644 --- a/src/marp-cli.ts +++ b/src/marp-cli.ts @@ -122,7 +122,7 @@ export const marpCli = async ( let watcherInstance: Watcher | undefined try { - const program = createYargs(argv) + const program = createYargs() .parserConfiguration({ 'dot-notation': false }) .usage(usage) .help(false) @@ -407,7 +407,7 @@ export const marpCli = async ( error(msg, CLIErrorCode.INVALID_OPTIONS) }) - const argvRet = await program.argv + const argvRet = await program.parseAsync(argv) const args = { baseUrl, // It's not intended using by the consumer so can't set through CLI arguments ...argvRet, diff --git a/src/utils/__mocks__/yargs.ts b/src/utils/__mocks__/yargs.ts deleted file mode 100644 index e15d20c9..00000000 --- a/src/utils/__mocks__/yargs.ts +++ /dev/null @@ -1,6 +0,0 @@ -const watcher = jest.requireActual('../yargs') -const { createYargs } = watcher - -watcher.createYargs = (...opts) => createYargs(...opts).locale('en') - -export = watcher diff --git a/src/utils/yargs.ts b/src/utils/yargs.ts index a8754701..3c6fc1f0 100644 --- a/src/utils/yargs.ts +++ b/src/utils/yargs.ts @@ -1,11 +1,15 @@ import type { Argv } from 'yargs' -import yargs from 'yargs/yargs' +import yargs from 'yargs' let currentYargsRef: WeakRef | null = null -export const createYargs = (...opts: Parameters) => { - const currentYargs = yargs(...opts) +export const createYargs = () => { + const currentYargs = yargs() currentYargsRef = new WeakRef(currentYargs) + + // Force to use English locale while testing + if (process.env.NODE_ENV === 'test') currentYargs.locale('en') + return currentYargs } diff --git a/test/marp-cli.ts b/test/marp-cli.ts index 30c7a358..d0a8d2ab 100644 --- a/test/marp-cli.ts +++ b/test/marp-cli.ts @@ -27,7 +27,6 @@ import { Watcher } from '../src/watcher' jest.mock('cosmiconfig') jest.mock('../src/preview') -jest.mock('../src/utils/yargs') jest.mock('../src/watcher', () => jest.createMockFromModule('../src/watcher')) const { Explorer } = cosmiconfigExplorer as any From 72cc262fb1d9ab8865ab0c24ff458dd1805e27ca Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 24 Jun 2025 22:05:29 +0900 Subject: [PATCH 2/2] Fix circular dependency warning that came from Marp CLI while building --- src/server.ts | 8 +++----- src/watcher.ts | 5 +++-- test/watcher.ts | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/server.ts b/src/server.ts index d9503359..f54f4646 100644 --- a/src/server.ts +++ b/src/server.ts @@ -20,9 +20,7 @@ import { CLIError, CLIErrorCode, error, isError } from './error' import { File, markdownExtensions } from './file' import serverIndex from './server/index.pug' import style from './server/index.scss' -import { notifier } from './watcher' - -export const watchNotifierWebSocketEntrypoint = '.__marp-cli-watch-notifier__' +import { WatchNotifier, notifier } from './watcher' export class Server extends (EventEmitter as new () => TypedEmitter) { readonly converter: Converter @@ -74,7 +72,7 @@ export class Server extends (EventEmitter as new () => TypedEmitter { - if (request.url?.startsWith(`/${watchNotifierWebSocketEntrypoint}/`)) { + if (request.url?.startsWith(`/${WatchNotifier.webSocketEntrypoint}/`)) { const ws = notifier.server if (ws) { @@ -197,7 +195,7 @@ export class Server extends (EventEmitter as new () => TypedEmitter { + .get(`/${WatchNotifier.webSocketEntrypoint}/*all`, (_, res) => { res.status(426).end('Upgrade Required') }) .get('*all', (req, res, next) => diff --git a/src/watcher.ts b/src/watcher.ts index 1bae6ee0..f4cdef24 100644 --- a/src/watcher.ts +++ b/src/watcher.ts @@ -8,7 +8,6 @@ import type { ServerOptions } from 'ws' import { Converter, ConvertedCallback } from './converter' import { isError } from './error' import { File, FileType } from './file' -import { watchNotifierWebSocketEntrypoint } from './server' import { debugWatcher, debugWatcherWS } from './utils/debug' const chokidarWatch: typeof _watch = (...args) => { @@ -100,6 +99,8 @@ export class WatchNotifier { private wss?: WebSocketServer private portNumber?: number + static readonly webSocketEntrypoint = '.__marp-cli-watch-notifier__' + get server() { return this.wss } @@ -128,7 +129,7 @@ export class WatchNotifier { entrypointType: WatchNotifierEntrypointType = 'static' ) { if (entrypointType === 'server') { - return `/${watchNotifierWebSocketEntrypoint}/${identifier}` + return `/${WatchNotifier.webSocketEntrypoint}/${identifier}` } const port = await this.port() diff --git a/test/watcher.ts b/test/watcher.ts index e6dbbebe..fb133867 100644 --- a/test/watcher.ts +++ b/test/watcher.ts @@ -1,7 +1,6 @@ import http from 'node:http' import { watch as chokidarWatch } from 'chokidar' import { File, FileType } from '../src/file' -import { watchNotifierWebSocketEntrypoint } from '../src/server' import { ThemeSet } from '../src/theme' import { Watcher, WatchNotifier, notifier } from '../src/watcher' @@ -224,7 +223,7 @@ describe('WatchNotifier', () => { it('generates WebSocket URL with relative path for server entrypoint if specified entrypoint type as "server"', async () => { const instance = new WatchNotifier() expect(await instance.register('test', 'server')).toBe( - `/${watchNotifierWebSocketEntrypoint}/${testIdentifier}` + `/${WatchNotifier.webSocketEntrypoint}/${testIdentifier}` ) }) })