-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
feat(cli,cli-service,cli-test-utils): add ts declaration #5356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
148b424
feat(cli-service): add declaration for PluginAPI
fangbinwei fc5fc9f
feat(cli): add declaration for GeneratorAPI,PromptModuleAPI
fangbinwei 49e8ab1
feat(cli-test-utils): add declaration for test utilities
fangbinwei 2d916e4
fix(cli-test-utils): fix ts declaration
fangbinwei f1ade53
fix(cli,cli-service,cli-test-utils): fix ts declaration
fangbinwei 1c7a4a6
chore: update yarn.lock
fangbinwei 490a82d
fix(cli,cli-service,cli-test-utils): fix ts declartation
fangbinwei 959087c
fix(cli-service,cli-test-utils): fix ts declaration
fangbinwei b43116b
style(cli,cli-service,cli-test-utils): change indent size
fangbinwei 1fb09d3
refactor(cli,cl-service): use readonly instead of getter in d.ts
fangbinwei 65c0c2e
fix(cli-service): fix type def of genCacheConfig in d.ts
fangbinwei 50e10b9
refactor(cli-test-utils): remove redundant type def in d.ts
fangbinwei 35ac3b6
fix(cli): fix extendPackage type def in d.ts
fangbinwei 7706a7d
chore: merge branch 'dev' of https://github.com/vuejs/vue-cli into dev
fangbinwei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ServicePlugin } from '@vue/cli-service' | ||
|
||
const servicePlugin: ServicePlugin = (api, options) => { | ||
const version = api.version | ||
api.assertVersion(4) | ||
api.assertVersion('^100') | ||
api.getCwd() | ||
api.resolve('src/main.js') | ||
api.hasPlugin('eslint') | ||
api.registerCommand( | ||
'lint', | ||
{ | ||
description: 'lint and fix source files', | ||
usage: 'vue-cli-service lint [options] [...files]', | ||
options: { | ||
'--format [formatter]': 'specify formatter (default: codeframe)' | ||
}, | ||
details: 'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options' | ||
}, | ||
args => { | ||
require('./lint')(args, api) | ||
} | ||
) | ||
api.registerCommand('lint', args => {}) | ||
|
||
api.chainWebpack(webpackConfig => { | ||
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') { | ||
webpackConfig.devtool('cheap-module-eval-source-map') | ||
|
||
webpackConfig.plugin('hmr').use(require('webpack/lib/HotModuleReplacementPlugin')) | ||
|
||
webpackConfig.output.globalObject(`(typeof self !== 'undefined' ? self : this)`) | ||
} | ||
}) | ||
|
||
api.configureWebpack(config => { | ||
config.output = { | ||
path: 'test-dist-2' | ||
} | ||
}) | ||
|
||
api.configureWebpack(config => { | ||
return { | ||
devtool: config.devtool || 'source-map' | ||
} | ||
}) | ||
|
||
api.resolveWebpackConfig() | ||
|
||
api.resolveWebpackConfig(api.resolveChainableWebpackConfig()) | ||
|
||
const { cacheIdentifier, cacheDirectory } = api.genCacheConfig( | ||
'babel-loader', | ||
{ | ||
'@babel/core': require('@babel/core/package.json').version, | ||
'@vue/babel-preset-app': require('@vue/babel-preset-app/package.json').version, | ||
'babel-loader': require('babel-loader/package.json').version, | ||
modern: !!process.env.VUE_CLI_MODERN_BUILD, | ||
browserslist: api.service.pkg.browserslist | ||
}, | ||
['babel.config.js', '.browserslistrc'] | ||
) | ||
} | ||
export = servicePlugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,137 @@ | ||
export { ProjectOptions, ConfigFunction } from './ProjectOptions' | ||
import minimist = require('minimist') | ||
import ChainableConfig = require('webpack-chain') | ||
import webpack = require('webpack') | ||
import WebpackDevServer = require('webpack-dev-server') | ||
import express = require('express') // @types/webpack-dev-server depends on @types/express | ||
import { ProjectOptions } from './ProjectOptions' | ||
|
||
type RegisterCommandFn = (args: minimist.ParsedArgs, rawArgv: string[]) => any | ||
|
||
type RegisterCommandOpts = Partial<{ | ||
description: string | ||
usage: string | ||
options: { | ||
[flags: string]: string | ||
} | ||
details: string | ||
}> | ||
|
||
type WebpackChainFn = (chainableConfig: ChainableConfig) => void | ||
|
||
type webpackRawConfigFn = ((config: webpack.Configuration) => webpack.Configuration | void) | webpack.Configuration | ||
|
||
type DevServerConfigFn = (app: express.Application, server: WebpackDevServer) => void | ||
|
||
interface CacheConfig { | ||
cacheDirectory: string | ||
cacheIdentifier: string | ||
} | ||
declare class PluginAPI { | ||
id: string | ||
|
||
service: any | ||
|
||
get version(): string | ||
|
||
assertVersion(range: number | string): void | ||
|
||
/** | ||
* Current working directory. | ||
*/ | ||
getCwd(): string | ||
|
||
/** | ||
* Resolve path for a project. | ||
* | ||
* @param _path - Relative path from project root | ||
* @return The resolved absolute path. | ||
*/ | ||
resolve(_path: string): string | ||
|
||
/** | ||
* Check if the project has a given plugin. | ||
* | ||
* @param id - Plugin id, can omit the (@vue/|vue-|@scope/vue)-cli-plugin- prefix | ||
* @return `boolean` | ||
*/ | ||
hasPlugin(id: string): boolean | ||
|
||
/** | ||
* Register a command that will become available as `vue-cli-service [name]`. | ||
* | ||
* @param name | ||
* @param [opts] | ||
* @param fn | ||
*/ | ||
registerCommand(name: string, fn: RegisterCommandFn): void | ||
registerCommand(name: string, opts: RegisterCommandOpts, fn: RegisterCommandFn): void | ||
|
||
/** | ||
* Register a function that will receive a chainable webpack config | ||
* the function is lazy and won't be called until `resolveWebpackConfig` is | ||
* called | ||
* | ||
* @param fn | ||
*/ | ||
chainWebpack(fn: WebpackChainFn): void | ||
|
||
/** | ||
* Register | ||
* - a webpack configuration object that will be merged into the config | ||
* OR | ||
* - a function that will receive the raw webpack config. | ||
* the function can either mutate the config directly or return an object | ||
* that will be merged into the config. | ||
* | ||
* @param fn | ||
*/ | ||
configureWebpack(fn: webpackRawConfigFn): void | ||
|
||
/** | ||
* Register a dev serve config function. It will receive the express `app` | ||
* instance of the dev server. | ||
* | ||
* @param fn | ||
*/ | ||
configureDevServer(fn: DevServerConfigFn): void | ||
|
||
/** | ||
* Resolve the final raw webpack config, that will be passed to webpack. | ||
* | ||
* @param [chainableConfig] | ||
* @return Raw webpack config. | ||
*/ | ||
resolveWebpackConfig(chainableConfig?: ChainableConfig): webpack.Configuration | ||
|
||
/** | ||
* Resolve an intermediate chainable webpack config instance, which can be | ||
* further tweaked before generating the final raw webpack config. | ||
* You can call this multiple times to generate different branches of the | ||
* base webpack config. | ||
* See https://github.com/mozilla-neutrino/webpack-chain | ||
* | ||
* @return ChainableWebpackConfig | ||
*/ | ||
resolveChainableWebpackConfig(): ChainableConfig | ||
|
||
/** | ||
* Generate a cache identifier from a number of variables | ||
*/ | ||
genCacheConfig(id: string, partialIdentifier: any, configFiles?: object | object[]): CacheConfig | ||
fangbinwei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Service plugin serves for modifying webpack config, | ||
* creating new vue-cli service commands or changing existing commands | ||
* | ||
* @param api - A PluginAPI instance | ||
* @param options - An object containing project local options specified in vue.config.js, | ||
* or in the "vue" field in package.json. | ||
*/ | ||
type ServicePlugin = ( | ||
api: PluginAPI, | ||
options: ProjectOptions | ||
) => any | ||
|
||
export { ProjectOptions, ServicePlugin, PluginAPI } | ||
export { ConfigFunction } from './ProjectOptions' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"files": [ | ||
"cli-service-test.ts", | ||
"index.d.ts", | ||
"ProjectOptions.d.ts" | ||
], | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"esModuleInterop": true, | ||
"strictFunctionTypes": true, | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"baseUrl": "." | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { PromptModuleAPI } from '@vue/cli' | ||
|
||
interface CliPromptModule { | ||
(api: PromptModuleAPI): void | ||
} | ||
|
||
declare function assertPromptModule( | ||
module: CliPromptModule | CliPromptModule[], | ||
expectedPrompts: object[], | ||
expectedOptions: object, | ||
opts?: { | ||
pluginsOnly?: boolean | ||
}, | ||
): Promise<void> | ||
|
||
export = assertPromptModule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Application } from 'express' | ||
|
||
declare function createJSONServer( | ||
/** | ||
* Either a path to a json file (e.g. 'db.json') or an object in memory | ||
* | ||
* Default: | ||
*{ | ||
* 'posts': [ | ||
* { 'id': 1, 'title': 'json-server', 'author': 'typicode' } | ||
* ], | ||
* 'comments': [ | ||
* { 'id': 1, 'body': 'some comment', 'postId': 1 } | ||
* ], | ||
* 'profile': { 'name': 'typicode' } | ||
*} | ||
*/ | ||
data?: string | object, | ||
): Application | ||
|
||
export = createJSONServer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// <reference types="node" /> | ||
import * as http from 'http' | ||
|
||
type Options = { | ||
[props: string]: any | ||
fangbinwei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Set a sub directory to be served | ||
*/ | ||
root: string | ||
} | ||
|
||
declare function createServer(options: Options): http.Server | ||
|
||
export = createServer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import execa = require('execa') // [email protected] needs @types/execa | ||
import { Preset } from '@vue/cli' | ||
|
||
/** | ||
* create project at path `cwd` | ||
*/ | ||
declare function createTestProject( | ||
/** | ||
* project name | ||
*/ | ||
name: string, | ||
/** | ||
* manual preset used to generate project. | ||
* | ||
* Example: | ||
* { | ||
* plugins: { | ||
* '@vue/cli-plugin-babel': {} | ||
* } | ||
* } | ||
*/ | ||
preset: Preset, | ||
/** `path.resolve(cwd, name)` will be the project's root directory */ | ||
cwd?: string | null, | ||
/** | ||
* if init git repo | ||
* | ||
* Default:`true` | ||
*/ | ||
initGit?: boolean, | ||
): Promise<{ | ||
/** test project's root path */ | ||
dir: string | ||
/** test if project contains the file */ | ||
has: (file: string) => boolean | ||
/** read the content for the file */ | ||
read: (file: string) => Promise<string> | ||
/** write file to project */ | ||
write: (file: string, content: any) => Promise<void> | ||
/** execa command at root path of project */ | ||
run: (command: string, args?: ReadonlyArray<string>) => execa.ExecaChildProcess | ||
/** delete the file of project */ | ||
rm: (file: string) => Promise<void> | ||
}> | ||
|
||
export = createTestProject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { GeneratorAPI, Preset } from '@vue/cli' | ||
|
||
type ApplyFn = ( | ||
api: GeneratorAPI, | ||
options: any, | ||
rootOptions: Preset, | ||
invoking: boolean, | ||
) => any | ||
interface Plugin { | ||
/** package name from plugin */ | ||
id: string | ||
/** generator function from plugin */ | ||
apply: ApplyFn | ||
/** parameter passed to generator function */ | ||
options?: any | ||
} | ||
|
||
/** | ||
* invoke generator function, and generate file tree in memory | ||
*/ | ||
declare function generateWithPlugin( | ||
plugin: Plugin | Plugin[], | ||
): Promise<{ | ||
/** package.json Object */ | ||
pkg: Record<string, any> | ||
/** virtual file tree, file path is the key of Object */ | ||
files: { | ||
[filePath: string]: string | Buffer | ||
} | ||
}> | ||
|
||
export = generateWithPlugin |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.