From 5ffef38ae42ae2bf5f1d0243af2925a5c4c8a0d8 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sat, 19 Feb 2022 13:08:12 +0800 Subject: [PATCH] fix --- packages/docusaurus-utils-build/bin/index.js | 11 ++++----- packages/docusaurus-utils-build/package.json | 21 ++++++++-------- packages/docusaurus-utils-build/src/build.ts | 13 +++++----- packages/docusaurus-utils-build/src/index.ts | 11 +++++++++ packages/docusaurus-utils-build/src/watch.ts | 24 +++++++------------ packages/docusaurus-utils-build/tsconfig.json | 1 + yarn.lock | 8 +++---- 7 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 packages/docusaurus-utils-build/src/index.ts diff --git a/packages/docusaurus-utils-build/bin/index.js b/packages/docusaurus-utils-build/bin/index.js index 0044ac69f32c..12aca2f9a0b9 100755 --- a/packages/docusaurus-utils-build/bin/index.js +++ b/packages/docusaurus-utils-build/bin/index.js @@ -5,10 +5,10 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -const chalk = require('chalk'); -const cli = require('commander'); -const build = require('../lib/build').default; -const watch = require('../lib/watch').default; + +import logger from '@docusaurus/logger'; +import cli from 'commander'; +import {build, watch} from '../lib/index.js'; cli .command('build') @@ -28,8 +28,7 @@ cli cli.arguments('').action((cmd) => { cli.outputHelp(); - console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`); - console.log(); + logger.error` Unknown command name=${cmd}.`; }); cli.parse(process.argv); diff --git a/packages/docusaurus-utils-build/package.json b/packages/docusaurus-utils-build/package.json index 30456c99cf36..916fb29f86e5 100644 --- a/packages/docusaurus-utils-build/package.json +++ b/packages/docusaurus-utils-build/package.json @@ -1,8 +1,9 @@ { "name": "@docusaurus/utils-build", - "version": "2.0.0-beta.14", + "version": "2.0.0-beta.15", "description": "Build and pack docusaurus plugins in one command", "license": "MIT", + "type": "module", "publishConfig": { "access": "public" }, @@ -18,21 +19,19 @@ "build": "tsc" }, "dependencies": { - "@babel/core": "^7.16.0", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0", - "@babel/plugin-proposal-optional-chaining": "^7.16.0", - "@babel/plugin-transform-modules-commonjs": "^7.16.0", - "@babel/preset-typescript": "^7.16.0", - "@docusaurus/utils": "2.0.0-beta.14", - "chalk": "^4.1.2", + "@babel/core": "^7.17.5", + "@babel/plugin-transform-modules-commonjs": "^7.16.8", + "@babel/preset-typescript": "^7.16.7", + "@docusaurus/logger": "2.0.0-beta.15", + "@docusaurus/utils": "2.0.0-beta.15", "chokidar": "^3.5.2", "commander": "^5.1.0", "lodash": "^4.17.21", "prettier": "^2.5.1", - "shelljs": "^0.8.4", - "typescript": "^4.5.2" + "shelljs": "^0.8.5", + "typescript": "^4.5.5" }, "devDependencies": { - "@docusaurus/types": "2.0.0-beta.14" + "@docusaurus/types": "2.0.0-beta.15" } } diff --git a/packages/docusaurus-utils-build/src/build.ts b/packages/docusaurus-utils-build/src/build.ts index a17c64ead743..29379b5fa037 100644 --- a/packages/docusaurus-utils-build/src/build.ts +++ b/packages/docusaurus-utils-build/src/build.ts @@ -6,8 +6,8 @@ */ import fs from 'fs'; -import chalk from 'chalk'; import {Globby} from '@docusaurus/utils'; +import logger from '@docusaurus/logger'; import Prettier from 'prettier'; import shelljs from 'shelljs'; import {compileOrCopy, compileServerCode, compileClientCode} from './compiler'; @@ -43,21 +43,20 @@ export default async function build( ignore = ['**/__tests__/**'], } = options; // Compile: src/*.ts -> lib/*.js - console.log(chalk.cyan('Compiling source with Babel...')); + logger.info('Compiling source with Babel...'); transformDir(sourceDir, targetDir, compileServerCode, [ ...ignore, '**/*.d.ts', ]); // Generate declaration: src/*.ts -> lib/*.d.ts // await tsc(sourceDir, targetDir, ignore); - console.log( - chalk.cyan('Typechecking and generating declaration with TSC...'), - ); + logger.info('Typechecking and generating declaration with TSC...'); const res = shelljs.exec('tsc --emitDeclarationOnly'); // 😅 if (res.code !== 0) { throw new Error('Typechecking failed.'); } - // Strip types & prettier: src/theme/*.tsx -> lib/theme/*.js (client code will be swizzlable) + // Strip types & format: src/theme/*.tsx -> lib/theme/*.js + // (client code will be swizzlable) if (fs.existsSync(themeDir)) { const prettierConfig = await Prettier.resolveConfig(themeDir); if (!prettierConfig) { @@ -65,7 +64,7 @@ export default async function build( 'Prettier config file not found. Building the theme code requires using Prettier to format the JS code, which will be used for swizzling.', ); } - console.log(chalk.cyan('Compiling theme with Babel + Prettier...')); + logger.info('Compiling theme with Babel + Prettier...'); transformDir( themeDir, themeTargetDir, diff --git a/packages/docusaurus-utils-build/src/index.ts b/packages/docusaurus-utils-build/src/index.ts new file mode 100644 index 000000000000..d2eb8a2401a2 --- /dev/null +++ b/packages/docusaurus-utils-build/src/index.ts @@ -0,0 +1,11 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import build from './build'; +import watch from './watch'; + +export {build, watch}; diff --git a/packages/docusaurus-utils-build/src/watch.ts b/packages/docusaurus-utils-build/src/watch.ts index 078f153694ce..6702a07c355e 100644 --- a/packages/docusaurus-utils-build/src/watch.ts +++ b/packages/docusaurus-utils-build/src/watch.ts @@ -8,7 +8,7 @@ import fs from 'fs'; import chokidar from 'chokidar'; import {debounce} from 'lodash'; -import chalk from 'chalk'; +import logger from '@docusaurus/logger'; import {compileOrCopy, compileClientCode, compileServerCode} from './compiler'; export default async function watch( @@ -45,26 +45,20 @@ export default async function watch( compileOrCopy(filePath, sourceDir, targetDir, compileServerCode); } } catch (e) { - console.log(chalk.red(`Error while processing ${chalk.cyan(filePath)}:`)); - console.error(e); + logger.error`Error while processing path=${filePath}:`; + logger.error(e); } }, 200); ['add', 'change'].forEach((event) => watcher.on(event, async (filePath: string) => { compile(filePath); - console.log( - chalk.green(`Compilation of ${chalk.cyan(filePath)} finished`), - ); + logger.success`Compilation of path=${filePath} finished`; }), ); - console.log( - chalk.green( - `Watching file changes in ${chalk.cyan(sourceDir)}${ - fs.existsSync(themeDir) - ? ` (server) and ${chalk.cyan(themeDir)} (client)` - : '' - }...`, - ), - ); + logger.info`Watching file changes in path=${sourceDir}${ + fs.existsSync(themeDir) + ? logger.interpolate` (server) and path=${themeDir} (client)` + : '' + }...`; } diff --git a/packages/docusaurus-utils-build/tsconfig.json b/packages/docusaurus-utils-build/tsconfig.json index c85b6f78938c..7b774a23a643 100644 --- a/packages/docusaurus-utils-build/tsconfig.json +++ b/packages/docusaurus-utils-build/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "incremental": true, + "module": "es2020", "tsBuildInfoFile": "./lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" diff --git a/yarn.lock b/yarn.lock index 6db36fc6b091..55f0bd16b564 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11106,11 +11106,11 @@ is-url@^1.2.4: integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww== is-weakref@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.1.tgz#842dba4ec17fa9ac9850df2d6efbc1737274f2a2" - integrity sha512-b2jKc2pQZjaeFYWEf7ScFj+Be1I+PXmlu572Q8coTXZ+LD/QQZ7ShPMst8h16riVgyXTQwUsFEl74mDvc/3MHQ== + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-weakref/-/is-weakref-1.0.2.tgz#9529f383a9338205e89765e0392efc2f100f06f2" + integrity sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ== dependencies: - call-bind "^1.0.0" + call-bind "^1.0.2" is-whitespace-character@^1.0.0: version "1.0.4"