From 19e73d7ea0ca71c1eb538b1eaf688165fe16308e Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sat, 29 Sep 2018 02:00:29 +0800 Subject: [PATCH] refactor($core): use upath --- packages/@vuepress/cli/index.js | 2 +- packages/@vuepress/core/__tests__/prepare/prepare.spec.js | 3 +-- packages/@vuepress/core/__tests__/prepare/util.js | 3 +-- packages/@vuepress/core/lib/build.js | 2 +- packages/@vuepress/core/lib/dev.js | 2 +- packages/@vuepress/core/lib/eject.js | 3 +-- packages/@vuepress/core/lib/internal-plugins/enhanceApp.js | 2 +- .../@vuepress/core/lib/internal-plugins/palette/index.js | 1 - packages/@vuepress/core/lib/internal-plugins/rootMixins.js | 2 +- packages/@vuepress/core/lib/internal-plugins/style/index.js | 5 ++--- .../@vuepress/core/lib/internal-plugins/transformModule.js | 3 +-- packages/@vuepress/core/lib/prepare/AppContext.js | 3 +-- packages/@vuepress/core/lib/prepare/Page.js | 3 +-- packages/@vuepress/core/lib/prepare/loadConfig.js | 3 +-- packages/@vuepress/core/lib/prepare/loadTheme.js | 3 +-- packages/@vuepress/core/lib/webpack/createBaseConfig.js | 3 +-- packages/@vuepress/core/lib/webpack/createClientConfig.js | 2 +- packages/@vuepress/core/lib/webpack/createServerConfig.js | 2 +- packages/@vuepress/markdown-loader/index.js | 3 +-- packages/@vuepress/plugin-active-header-links/index.js | 2 +- packages/@vuepress/plugin-back-to-top/index.js | 2 +- packages/@vuepress/plugin-blog/index.js | 3 +-- packages/@vuepress/plugin-google-analytics/index.js | 2 +- packages/@vuepress/plugin-i18n-ui/index.js | 2 +- packages/@vuepress/plugin-medium-zoom/index.js | 2 +- packages/@vuepress/plugin-pagination/index.js | 2 +- packages/@vuepress/plugin-pwa/index.js | 3 +-- packages/@vuepress/plugin-register-components/index.js | 3 +-- packages/@vuepress/plugin-search/index.js | 2 +- packages/@vuepress/shared-utils/index.js | 1 + packages/@vuepress/shared-utils/lib/module.js | 2 +- .../@vuepress/shared-utils/lib/shortcutPackageResolver.js | 2 +- packages/@vuepress/shared-utils/package.json | 3 ++- packages/@vuepress/test-utils/jest/jest.config.js | 2 +- packages/@vuepress/theme-default/plugin.js | 2 +- scripts/bootstrap.js | 2 +- scripts/jest.config.js | 2 +- yarn.lock | 2 +- 38 files changed, 39 insertions(+), 52 deletions(-) diff --git a/packages/@vuepress/cli/index.js b/packages/@vuepress/cli/index.js index 9c846e4858..c23a6618f5 100644 --- a/packages/@vuepress/cli/index.js +++ b/packages/@vuepress/cli/index.js @@ -30,7 +30,7 @@ exports.bootstrap = function ({ plugins, theme } = {}) { - const path = require('path') + const { path } = require('@vuepress/shared-utils') const { dev, build, eject } = require('@vuepress/core') program diff --git a/packages/@vuepress/core/__tests__/prepare/prepare.spec.js b/packages/@vuepress/core/__tests__/prepare/prepare.spec.js index 420ebaaddc..0e0ef5837b 100644 --- a/packages/@vuepress/core/__tests__/prepare/prepare.spec.js +++ b/packages/@vuepress/core/__tests__/prepare/prepare.spec.js @@ -1,5 +1,4 @@ -const { fs } = require('@vuepress/shared-utils') -const path = require('path') +const { fs, path } = require('@vuepress/shared-utils') const prepare = require('../../lib/prepare') const docsBaseDir = path.resolve(__dirname, 'fixtures') diff --git a/packages/@vuepress/core/__tests__/prepare/util.js b/packages/@vuepress/core/__tests__/prepare/util.js index edb2bf37e3..6a9267eb00 100644 --- a/packages/@vuepress/core/__tests__/prepare/util.js +++ b/packages/@vuepress/core/__tests__/prepare/util.js @@ -1,5 +1,4 @@ -const path = require('path') -const { fs } = require('@vuepress/shared-utils') +const { fs, path } = require('@vuepress/shared-utils') const AppContext = require('../../lib/prepare/AppContext') const createMarkdown = require('../../../markdown/lib/index') diff --git a/packages/@vuepress/core/lib/build.js b/packages/@vuepress/core/lib/build.js index 5c4fe16929..483eca5405 100644 --- a/packages/@vuepress/core/lib/build.js +++ b/packages/@vuepress/core/lib/build.js @@ -3,7 +3,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) { process.env.NODE_ENV = 'production' - const path = require('path') + const { path } = require('@vuepress/shared-utils') const webpack = require('webpack') const readline = require('readline') const escape = require('escape-html') diff --git a/packages/@vuepress/core/lib/dev.js b/packages/@vuepress/core/lib/dev.js index a70585bb05..7e0a4a4907 100644 --- a/packages/@vuepress/core/lib/dev.js +++ b/packages/@vuepress/core/lib/dev.js @@ -1,7 +1,7 @@ 'use strict' module.exports = async function dev (sourceDir, cliOptions = {}) { - const path = require('path') + const { path } = require('@vuepress/shared-utils') const webpack = require('webpack') const chokidar = require('chokidar') const serve = require('webpack-serve') diff --git a/packages/@vuepress/core/lib/eject.js b/packages/@vuepress/core/lib/eject.js index 4b37895205..c3a2f44096 100644 --- a/packages/@vuepress/core/lib/eject.js +++ b/packages/@vuepress/core/lib/eject.js @@ -1,7 +1,6 @@ 'use strict' -const path = require('path') -const { chalk, fs, logger } = require('@vuepress/shared-utils') +const { path, chalk, fs, logger } = require('@vuepress/shared-utils') module.exports = async (dir) => { try { diff --git a/packages/@vuepress/core/lib/internal-plugins/enhanceApp.js b/packages/@vuepress/core/lib/internal-plugins/enhanceApp.js index 1163d3187b..5aa987c38a 100644 --- a/packages/@vuepress/core/lib/internal-plugins/enhanceApp.js +++ b/packages/@vuepress/core/lib/internal-plugins/enhanceApp.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = (options, context) => ({ name: '@vuepress/internal-enhance-app', diff --git a/packages/@vuepress/core/lib/internal-plugins/palette/index.js b/packages/@vuepress/core/lib/internal-plugins/palette/index.js index 67553d7bc5..38d071beae 100644 --- a/packages/@vuepress/core/lib/internal-plugins/palette/index.js +++ b/packages/@vuepress/core/lib/internal-plugins/palette/index.js @@ -20,7 +20,6 @@ module.exports = (options, ctx) => ({ // user's palette can override theme's palette. const paletteContent = themePaletteContent + userPaletteContent - console.log(paletteContent) await writeTemp('palette.styl', paletteContent) } }) diff --git a/packages/@vuepress/core/lib/internal-plugins/rootMixins.js b/packages/@vuepress/core/lib/internal-plugins/rootMixins.js index 38edf4c52a..929f29f092 100644 --- a/packages/@vuepress/core/lib/internal-plugins/rootMixins.js +++ b/packages/@vuepress/core/lib/internal-plugins/rootMixins.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') const { codegen: { pathsToModuleCode }} = require('@vuepress/shared-utils') module.exports = (options, context, api) => ({ diff --git a/packages/@vuepress/core/lib/internal-plugins/style/index.js b/packages/@vuepress/core/lib/internal-plugins/style/index.js index 775466ebe8..8a8190ee3b 100644 --- a/packages/@vuepress/core/lib/internal-plugins/style/index.js +++ b/packages/@vuepress/core/lib/internal-plugins/style/index.js @@ -1,5 +1,4 @@ -const path = require('path') -const { fs, logger, chalk } = require('@vuepress/shared-utils') +const { fs, path, logger, chalk } = require('@vuepress/shared-utils') module.exports = (options, context) => ({ name: '@vuepress/internal-style', @@ -17,7 +16,7 @@ module.exports = (options, context) => ({ } // style.styl API. - const stylePath = path.resolve(sourceDir, '.vuepress/style.styl').replace(/[\\]+/g, '/') + const stylePath = path.resolve(sourceDir, '.vuepress/style.styl') const hasUserStyle = fs.existsSync(stylePath) await writeTemp('style.styl', hasUserStyle ? `@import(${JSON.stringify(stylePath)})` : ``) diff --git a/packages/@vuepress/core/lib/internal-plugins/transformModule.js b/packages/@vuepress/core/lib/internal-plugins/transformModule.js index 10c60a3a76..015cfe7c23 100644 --- a/packages/@vuepress/core/lib/internal-plugins/transformModule.js +++ b/packages/@vuepress/core/lib/internal-plugins/transformModule.js @@ -1,5 +1,4 @@ -const path = require('path') -const { fs } = require('@vuepress/shared-utils') +const { fs, path } = require('@vuepress/shared-utils') const DIR = 'transform' diff --git a/packages/@vuepress/core/lib/prepare/AppContext.js b/packages/@vuepress/core/lib/prepare/AppContext.js index 0733514051..157e87d44b 100644 --- a/packages/@vuepress/core/lib/prepare/AppContext.js +++ b/packages/@vuepress/core/lib/prepare/AppContext.js @@ -4,12 +4,11 @@ * Module dependencies. */ -const path = require('path') const createMarkdown = require('./createMarkdown') const loadConfig = require('./loadConfig') const loadTheme = require('./loadTheme') const { - fs, logger, chalk, globby, sort, + fs, path, logger, chalk, globby, sort, datatypes: { isFunction }, fallback: { fsExistsFallback } } = require('@vuepress/shared-utils') diff --git a/packages/@vuepress/core/lib/prepare/Page.js b/packages/@vuepress/core/lib/prepare/Page.js index af4cdba7f5..cffd130e00 100644 --- a/packages/@vuepress/core/lib/prepare/Page.js +++ b/packages/@vuepress/core/lib/prepare/Page.js @@ -4,10 +4,9 @@ * Module dependencies. */ -const path = require('path') const slugify = require('../../../markdown/lib/slugify') const { inferDate, DATE_RE } = require('../util/index') -const { extractHeaders, fs, fileToPath, parseFrontmatter, getPermalink, inferTitle } = require('@vuepress/shared-utils') +const { extractHeaders, fs, path, fileToPath, parseFrontmatter, getPermalink, inferTitle } = require('@vuepress/shared-utils') /** * Expose Page class. diff --git a/packages/@vuepress/core/lib/prepare/loadConfig.js b/packages/@vuepress/core/lib/prepare/loadConfig.js index a6f264bf7e..c786e88d44 100644 --- a/packages/@vuepress/core/lib/prepare/loadConfig.js +++ b/packages/@vuepress/core/lib/prepare/loadConfig.js @@ -4,8 +4,7 @@ * Module dependencies. */ -const { fs } = require('@vuepress/shared-utils') -const path = require('path') +const { fs, path } = require('@vuepress/shared-utils') const yamlParser = require('js-yaml') const tomlParser = require('toml') diff --git a/packages/@vuepress/core/lib/prepare/loadTheme.js b/packages/@vuepress/core/lib/prepare/loadTheme.js index 7a73f3f7ef..5261bb22b2 100644 --- a/packages/@vuepress/core/lib/prepare/loadTheme.js +++ b/packages/@vuepress/core/lib/prepare/loadTheme.js @@ -4,9 +4,8 @@ * Module dependencies. */ -const path = require('path') -const fs = require('fs') const { + fs, path, shortcutPackageResolver: { resolveTheme }, datatypes: { isString }, logger, chalk diff --git a/packages/@vuepress/core/lib/webpack/createBaseConfig.js b/packages/@vuepress/core/lib/webpack/createBaseConfig.js index dd7969203c..667cf12ff2 100644 --- a/packages/@vuepress/core/lib/webpack/createBaseConfig.js +++ b/packages/@vuepress/core/lib/webpack/createBaseConfig.js @@ -4,8 +4,7 @@ * Module dependencies. */ -const path = require('path') -const { fs, logger, chalk } = require('@vuepress/shared-utils') +const { fs, path, logger, chalk } = require('@vuepress/shared-utils') /** * Expose createBaseConfig method. diff --git a/packages/@vuepress/core/lib/webpack/createClientConfig.js b/packages/@vuepress/core/lib/webpack/createClientConfig.js index c818c29310..79a82e427f 100644 --- a/packages/@vuepress/core/lib/webpack/createClientConfig.js +++ b/packages/@vuepress/core/lib/webpack/createClientConfig.js @@ -5,7 +5,7 @@ */ module.exports = function createClientConfig (ctx) { - const path = require('path') + const { path } = require('@vuepress/shared-utils') const WebpackBar = require('webpackbar') const createBaseConfig = require('./createBaseConfig') diff --git a/packages/@vuepress/core/lib/webpack/createServerConfig.js b/packages/@vuepress/core/lib/webpack/createServerConfig.js index b8592a98fa..33aeb33321 100644 --- a/packages/@vuepress/core/lib/webpack/createServerConfig.js +++ b/packages/@vuepress/core/lib/webpack/createServerConfig.js @@ -6,7 +6,7 @@ module.exports = function createServerConfig (ctx) { const fs = require('fs') - const path = require('path') + const { path } = require('@vuepress/shared-utils') const WebpackBar = require('webpackbar') const createBaseConfig = require('./createBaseConfig') const VueSSRServerPlugin = require('vue-server-renderer/server-plugin') diff --git a/packages/@vuepress/markdown-loader/index.js b/packages/@vuepress/markdown-loader/index.js index fd35030157..7d58ce5fac 100644 --- a/packages/@vuepress/markdown-loader/index.js +++ b/packages/@vuepress/markdown-loader/index.js @@ -4,10 +4,9 @@ * Module dependencies. */ -const path = require('path') const { EventEmitter } = require('events') const { getOptions } = require('loader-utils') -const { fs, hash, parseFrontmatter, inferTitle, extractHeaders } = require('@vuepress/shared-utils') +const { fs, path, hash, parseFrontmatter, inferTitle, extractHeaders } = require('@vuepress/shared-utils') const LRU = require('lru-cache') const md = require('@vuepress/markdown') diff --git a/packages/@vuepress/plugin-active-header-links/index.js b/packages/@vuepress/plugin-active-header-links/index.js index 7831662368..04eea8cdea 100644 --- a/packages/@vuepress/plugin-active-header-links/index.js +++ b/packages/@vuepress/plugin-active-header-links/index.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = { clientRootMixin: path.resolve(__dirname, 'mixin.js') diff --git a/packages/@vuepress/plugin-back-to-top/index.js b/packages/@vuepress/plugin-back-to-top/index.js index ecfc0b64cf..63a99d443c 100644 --- a/packages/@vuepress/plugin-back-to-top/index.js +++ b/packages/@vuepress/plugin-back-to-top/index.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = (options, context) => ({ enhanceAppFiles: [ diff --git a/packages/@vuepress/plugin-blog/index.js b/packages/@vuepress/plugin-blog/index.js index d09ddc6d2b..c7ccbe102d 100644 --- a/packages/@vuepress/plugin-blog/index.js +++ b/packages/@vuepress/plugin-blog/index.js @@ -1,5 +1,4 @@ -const path = require('path') -const { datatypes: { isString }} = require('@vuepress/shared-utils') +const { path, datatypes: { isString }} = require('@vuepress/shared-utils') module.exports = (options, ctx) => { const { layoutComponentMap } = ctx diff --git a/packages/@vuepress/plugin-google-analytics/index.js b/packages/@vuepress/plugin-google-analytics/index.js index cb94b78ed8..f0f01f1951 100644 --- a/packages/@vuepress/plugin-google-analytics/index.js +++ b/packages/@vuepress/plugin-google-analytics/index.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = (options = {}, context) => ({ define () { diff --git a/packages/@vuepress/plugin-i18n-ui/index.js b/packages/@vuepress/plugin-i18n-ui/index.js index 2639f197db..d42003a46f 100644 --- a/packages/@vuepress/plugin-i18n-ui/index.js +++ b/packages/@vuepress/plugin-i18n-ui/index.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = (pluginOptions = {}, context) => ({ name: 'i18n-ui', diff --git a/packages/@vuepress/plugin-medium-zoom/index.js b/packages/@vuepress/plugin-medium-zoom/index.js index 7831662368..04eea8cdea 100644 --- a/packages/@vuepress/plugin-medium-zoom/index.js +++ b/packages/@vuepress/plugin-medium-zoom/index.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = { clientRootMixin: path.resolve(__dirname, 'mixin.js') diff --git a/packages/@vuepress/plugin-pagination/index.js b/packages/@vuepress/plugin-pagination/index.js index 407ff4a904..d078e4c0f3 100644 --- a/packages/@vuepress/plugin-pagination/index.js +++ b/packages/@vuepress/plugin-pagination/index.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') function getIntervallers (max, interval) { const count = Math.floor(max / interval) diff --git a/packages/@vuepress/plugin-pwa/index.js b/packages/@vuepress/plugin-pwa/index.js index a7d17140b7..26e21d9e3e 100644 --- a/packages/@vuepress/plugin-pwa/index.js +++ b/packages/@vuepress/plugin-pwa/index.js @@ -1,5 +1,4 @@ -const path = require('path') -const { logger, fs } = require('@vuepress/shared-utils') +const { logger, fs, path } = require('@vuepress/shared-utils') module.exports = (options, context) => ({ ready () { diff --git a/packages/@vuepress/plugin-register-components/index.js b/packages/@vuepress/plugin-register-components/index.js index 3496d86a4d..f3f548c643 100644 --- a/packages/@vuepress/plugin-register-components/index.js +++ b/packages/@vuepress/plugin-register-components/index.js @@ -1,5 +1,4 @@ -const { fs, globby } = require('@vuepress/shared-utils') -const path = require('path') +const { fs, path, globby } = require('@vuepress/shared-utils') function fileToComponentName (file) { return file diff --git a/packages/@vuepress/plugin-search/index.js b/packages/@vuepress/plugin-search/index.js index 7c7bf52852..c0ffe03d7c 100644 --- a/packages/@vuepress/plugin-search/index.js +++ b/packages/@vuepress/plugin-search/index.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = (options) => ({ alias: { diff --git a/packages/@vuepress/shared-utils/index.js b/packages/@vuepress/shared-utils/index.js index 3fa8fc3051..11590320f0 100644 --- a/packages/@vuepress/shared-utils/index.js +++ b/packages/@vuepress/shared-utils/index.js @@ -25,6 +25,7 @@ exports.extractHeaders = require('./lib/extractHeaders') exports.chalk = require('chalk') exports.fs = require('fs-extra') +exports.path = require('upath') exports.globby = require('globby') exports.hash = require('hash-sum') diff --git a/packages/@vuepress/shared-utils/lib/module.js b/packages/@vuepress/shared-utils/lib/module.js index 371c57758e..5cce825f06 100644 --- a/packages/@vuepress/shared-utils/lib/module.js +++ b/packages/@vuepress/shared-utils/lib/module.js @@ -1,7 +1,7 @@ // Midified from https://github.com/vuejs/vue-cli/blob/dev/packages/@0vue/cli-shared-utils/lib/module.js const semver = require('semver') -const path = require('path') +const path = require('upath') const fs = require('fs-extra') const { isTest } = require('./env') diff --git a/packages/@vuepress/shared-utils/lib/shortcutPackageResolver.js b/packages/@vuepress/shared-utils/lib/shortcutPackageResolver.js index e91f850d1b..da80a5fa84 100644 --- a/packages/@vuepress/shared-utils/lib/shortcutPackageResolver.js +++ b/packages/@vuepress/shared-utils/lib/shortcutPackageResolver.js @@ -1,5 +1,5 @@ const fs = require('fs') -const path = require('path') +const path = require('upath') const chalk = require('chalk') const { isDebug } = require('./env') const { resolveModule, loadModule } = require('./module') diff --git a/packages/@vuepress/shared-utils/package.json b/packages/@vuepress/shared-utils/package.json index 358473a2a9..4f20b3c144 100644 --- a/packages/@vuepress/shared-utils/package.json +++ b/packages/@vuepress/shared-utils/package.json @@ -21,7 +21,8 @@ "escape-html": "^1.0.3", "fs-extra": "^5.0.0", "globby": "^8.0.1", - "hash-sum": "^1.0.2" + "hash-sum": "^1.0.2", + "upath": "^1.1.0" }, "author": "ULIVZ ", "license": "MIT", diff --git a/packages/@vuepress/test-utils/jest/jest.config.js b/packages/@vuepress/test-utils/jest/jest.config.js index a6e7eff73a..0907d1a105 100644 --- a/packages/@vuepress/test-utils/jest/jest.config.js +++ b/packages/@vuepress/test-utils/jest/jest.config.js @@ -1,7 +1,7 @@ // https://github.com/facebook/jest/tree/master/packages/babel-jest // TODO remove 'babel-core@^7.0.0-0' when babel-jest can work with '@babel/core' -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = { rootDir: path.resolve(__dirname, '..'), diff --git a/packages/@vuepress/theme-default/plugin.js b/packages/@vuepress/theme-default/plugin.js index 1aee3b5bbf..ff415d9654 100644 --- a/packages/@vuepress/theme-default/plugin.js +++ b/packages/@vuepress/theme-default/plugin.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') module.exports = (options, context) => ({ name: 'default-theme', diff --git a/scripts/bootstrap.js b/scripts/bootstrap.js index 8b5736df47..c9dd1ff0a9 100644 --- a/scripts/bootstrap.js +++ b/scripts/bootstrap.js @@ -1,7 +1,7 @@ // create package.json and README for packages that don't have one yet const fs = require('fs') -const path = require('path') +const { path } = require('@vuepress/shared-utils') const baseVersion = require('../packages/@vuepress/core/package.json').version const packagesDir = path.resolve(__dirname, '../packages/@vuepress') diff --git a/scripts/jest.config.js b/scripts/jest.config.js index dcb002f565..d7fe7bdc74 100644 --- a/scripts/jest.config.js +++ b/scripts/jest.config.js @@ -1,4 +1,4 @@ -const path = require('path') +const { path } = require('@vuepress/shared-utils') const createJestConfig = require('@vuepress/test-utils/createJestConfig') module.exports = createJestConfig({ diff --git a/yarn.lock b/yarn.lock index fa9662a341..f997163ff3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8891,7 +8891,7 @@ unzip-response@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97" -upath@^1.0.5: +upath@^1.0.5, upath@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/upath/-/upath-1.1.0.tgz#35256597e46a581db4793d0ce47fa9aebfc9fabd"