Skip to content

Add ts declaration for @vue/cli-test-utils, Plugin API, Generator API #5324

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

Closed
fangbinwei opened this issue Mar 26, 2020 · 1 comment
Closed

Comments

@fangbinwei
Copy link
Collaborator

What problem does this feature solve?

I code by vscode, and these is no code intelliSense when coding vue-cli-plugin and plugin unit test.

If ts declarations are provided, it will be helpful. I'm maintaing some vue cli plugins for some times, it's just a pain point for me.

What does the proposed API look like?

for @vue/cli-test-utils, add declaration to cli-test-utils folder, like createTestProject.d.ts, vscode can finish code completion even in .js file.

for plugin, generator api, maybe like this?

import {GeneratorAPI} from '@vue/cli'
import {PluginAPI} from '@vue/cli-service'

or

import {GeneratorAPI, PluginAPI} from '@vue/cli-types'

export =  function (api: GeneratorAPI, options: any) {

}
@shadowings-zy
Copy link

Hi, I am interested in this issue and I had generated GeneratorAPI declaration file and PluginAPI declaration file like this:

/**
 * Note: if a plugin-registered command needs to run in a specific default mode,
 * the plugin needs to expose it via `module.exports.defaultModes` in the form
 * of { [commandName]: mode }. This is because the command mode needs to be
 * known and applied before loading user options / applying plugins.
 */
declare interface PluginAPI {
  /**
   *
   * @param id
   * @param service
   */
  new (id: string, service: any);

  /**
   *
   * @param range
   */
  assertVersion(range: string): void;

  /**
   * Current working directory.
   * @return
   */
  getCwd(): any;

  /**
   * Resolve path for a project.
   *
   * @param {string} _path - Relative path from project root
   * @return {string} The resolved absolute path.
   */
  resolve(_path: string): string;

  /**
   * Check if the project has a given plugin.
   *
   * @param {string} 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 {string} name
   * @param {object} [opts]
   *   {
   *     description: string,
   *     usage: string,
   *     options: { [string]: string }
   *   }
   * @param {function} fn
   *   (args: { [string]: string }, rawArgs: string[]) => ?Promise
   */
  registerCommand(name: string, opts?: any, fn: any): 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 {function} fn
   */
  chainWebpack(fn: any): 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 {object | function} fn
   */
  configureWebpack(fn: any): void;

  /**
   * Register a dev serve config function. It will receive the express `app`
   * instance of the dev server.
   *
   * @param {function} fn
   */
  configureDevServer(fn: any): void;

  /**
   * Resolve the final raw webpack config, that will be passed to webpack.
   *
   * @param {ChainableWebpackConfig} [chainableConfig]
   * @return {object} Raw webpack config.
   */
  resolveWebpackConfig(chainableConfig?: any): any;

  /**
   * 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(): any;

  /**
   * Generate a cache identifier from a number of variables
   * @param id
   * @param partialIdentifier
   * @param configFiles
   * @return
   */
  genCacheConfig(id: any, partialIdentifier: any, configFiles: any): any;
}

But 'add declaration for @vue/cli-test-utils, like createTestProject.d.ts' makes me confused, because there is only a function in createTestProject.js.
We just need to add declaration for this function in the declaration file, right?
If so, I will work on it.

fangbinwei added a commit to fangbinwei/vue-cli that referenced this issue Apr 5, 2020
fangbinwei added a commit to fangbinwei/vue-cli that referenced this issue Apr 5, 2020
fangbinwei added a commit to fangbinwei/vue-cli that referenced this issue Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants