@vuepress/core 2.0.0-beta.38 → 2.0.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/lib/app/appUse.d.ts +2 -2
  2. package/lib/app/appUse.js +14 -9
  3. package/lib/app/createBaseApp.js +2 -4
  4. package/lib/app/createBuildApp.js +1 -2
  5. package/lib/app/createDevApp.js +1 -2
  6. package/lib/app/index.d.ts +0 -5
  7. package/lib/app/index.js +0 -5
  8. package/lib/app/prepare/preparePagesRoutes.js +36 -37
  9. package/lib/app/resolveAppOptions.d.ts +1 -1
  10. package/lib/app/resolveAppOptions.js +12 -18
  11. package/lib/app/resolvePluginObject.d.ts +2 -2
  12. package/lib/app/resolvePluginObject.js +1 -14
  13. package/lib/app/resolveThemeInfo.d.ts +2 -2
  14. package/lib/app/resolveThemeInfo.js +8 -12
  15. package/lib/app/setupAppThemeAndPlugins.d.ts +5 -0
  16. package/lib/app/{setupAppTheme.js → setupAppThemeAndPlugins.js} +8 -7
  17. package/lib/page/createPage.js +0 -1
  18. package/lib/page/resolvePageComponentInfo.d.ts +1 -2
  19. package/lib/page/resolvePageComponentInfo.js +1 -1
  20. package/lib/types/app/app.d.ts +5 -5
  21. package/lib/types/app/options.d.ts +51 -12
  22. package/lib/types/bundler.d.ts +3 -24
  23. package/lib/types/plugin.d.ts +4 -20
  24. package/lib/types/theme.d.ts +6 -20
  25. package/package.json +16 -13
  26. package/lib/app/normalizePluginConfig.d.ts +0 -2
  27. package/lib/app/normalizePluginConfig.js +0 -15
  28. package/lib/app/resolveBundler.d.ts +0 -2
  29. package/lib/app/resolveBundler.js +0 -10
  30. package/lib/app/resolvePluginModule.d.ts +0 -5
  31. package/lib/app/resolvePluginModule.js +0 -20
  32. package/lib/app/resolvePluginsFromConfig.d.ts +0 -5
  33. package/lib/app/resolvePluginsFromConfig.js +0 -16
  34. package/lib/app/resolveThemeObject.d.ts +0 -5
  35. package/lib/app/resolveThemeObject.js +0 -22
  36. package/lib/app/setupAppPlugins.d.ts +0 -5
  37. package/lib/app/setupAppPlugins.js +0 -14
  38. package/lib/app/setupAppTheme.d.ts +0 -5
@@ -1,2 +1,2 @@
1
- import type { App, Plugin, PluginOptions } from '../types';
2
- export declare const appUse: <T extends PluginOptions>(app: App, rawPlugin: string | Plugin<T, import("../types").PluginObject>, config?: Partial<T> | undefined) => App;
1
+ import type { App, Plugin } from '../types';
2
+ export declare const appUse: (app: App, rawPlugin: Plugin) => App;
package/lib/app/appUse.js CHANGED
@@ -4,20 +4,25 @@ exports.appUse = void 0;
4
4
  const utils_1 = require("@vuepress/utils");
5
5
  const resolvePluginObject_1 = require("./resolvePluginObject");
6
6
  const log = (0, utils_1.debug)('vuepress:core/app');
7
- const appUse = (app, rawPlugin, config) => {
8
- const plugin = (0, resolvePluginObject_1.resolvePluginObject)(app, rawPlugin, config);
9
- log(`use plugin ${utils_1.chalk.magenta(plugin.name)}`);
10
- if (plugin.multiple !== true) {
11
- // remove duplicated plugin
12
- const duplicateIndex = app.pluginApi.plugins.findIndex(({ name }) => name === plugin.name);
7
+ const appUse = (app, rawPlugin) => {
8
+ const pluginObject = (0, resolvePluginObject_1.resolvePluginObject)(app, rawPlugin);
9
+ // ignore anonymous plugins or theme
10
+ if (!pluginObject.name) {
11
+ (0, utils_1.warn)(`an anonymous plugin or theme was detected and ignored`);
12
+ return app;
13
+ }
14
+ log(`use plugin ${utils_1.chalk.magenta(pluginObject.name)}`);
15
+ // handle duplicated plugins
16
+ if (pluginObject.multiple !== true) {
17
+ const duplicateIndex = app.pluginApi.plugins.findIndex(({ name }) => name === pluginObject.name);
13
18
  if (duplicateIndex !== -1) {
19
+ // remove the previous duplicated plugin
14
20
  app.pluginApi.plugins.splice(duplicateIndex, 1);
15
- // show warning when duplicate plugins are detected
16
- (0, utils_1.warn)(`plugin ${utils_1.chalk.magenta(plugin.name)} has been used multiple times, only the last one will take effect`);
21
+ (0, utils_1.warn)(`plugin ${utils_1.chalk.magenta(pluginObject.name)} has been used multiple times, only the last one will take effect`);
17
22
  }
18
23
  }
19
24
  // use plugin
20
- app.pluginApi.plugins.push(plugin);
25
+ app.pluginApi.plugins.push(pluginObject);
21
26
  return app;
22
27
  };
23
28
  exports.appUse = appUse;
@@ -11,8 +11,7 @@ const resolveAppOptions_1 = require("./resolveAppOptions");
11
11
  const resolveAppSiteData_1 = require("./resolveAppSiteData");
12
12
  const resolveAppVersion_1 = require("./resolveAppVersion");
13
13
  const resolveAppWriteTemp_1 = require("./resolveAppWriteTemp");
14
- const setupAppPlugins_1 = require("./setupAppPlugins");
15
- const setupAppTheme_1 = require("./setupAppTheme");
14
+ const setupAppThemeAndPlugins_1 = require("./setupAppThemeAndPlugins");
16
15
  /**
17
16
  * Create vuepress app
18
17
  */
@@ -41,8 +40,7 @@ const createBaseApp = (config, isBuild = false) => {
41
40
  // setup theme and plugins
42
41
  // notice that we setup theme before plugins,
43
42
  // so user plugins could override theme plugins
44
- (0, setupAppTheme_1.setupAppTheme)(app, config);
45
- (0, setupAppPlugins_1.setupAppPlugins)(app);
43
+ (0, setupAppThemeAndPlugins_1.setupAppThemeAndPlugins)(app, config);
46
44
  return app;
47
45
  };
48
46
  exports.createBaseApp = createBaseApp;
@@ -2,13 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createBuildApp = void 0;
4
4
  const createBaseApp_1 = require("./createBaseApp");
5
- const resolveBundler_1 = require("./resolveBundler");
6
5
  /**
7
6
  * Create vuepress build app
8
7
  */
9
8
  const createBuildApp = (config) => {
10
9
  const app = (0, createBaseApp_1.createBaseApp)(config, true);
11
- app.build = () => (0, resolveBundler_1.resolveBundler)(app.options).build(app);
10
+ app.build = () => app.options.bundler.build(app);
12
11
  return app;
13
12
  };
14
13
  exports.createBuildApp = createBuildApp;
@@ -2,13 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createDevApp = void 0;
4
4
  const createBaseApp_1 = require("./createBaseApp");
5
- const resolveBundler_1 = require("./resolveBundler");
6
5
  /**
7
6
  * Create vuepress dev app
8
7
  */
9
8
  const createDevApp = (config) => {
10
9
  const app = (0, createBaseApp_1.createBaseApp)(config, false);
11
- app.dev = () => (0, resolveBundler_1.resolveBundler)(app.options).dev(app);
10
+ app.dev = () => app.options.bundler.dev(app);
12
11
  return app;
13
12
  };
14
13
  exports.createDevApp = createDevApp;
@@ -5,7 +5,6 @@ export * from './appUse';
5
5
  export * from './createBaseApp';
6
6
  export * from './createBuildApp';
7
7
  export * from './createDevApp';
8
- export * from './normalizePluginConfig';
9
8
  export * from './resolveAppDir';
10
9
  export * from './resolveAppEnv';
11
10
  export * from './resolveAppOptions';
@@ -13,10 +12,6 @@ export * from './resolveAppPages';
13
12
  export * from './resolveAppSiteData';
14
13
  export * from './resolveAppVersion';
15
14
  export * from './resolveAppWriteTemp';
16
- export * from './resolveBundler';
17
15
  export * from './resolvePluginObject';
18
- export * from './resolvePluginModule';
19
- export * from './resolvePluginsFromConfig';
20
- export * from './resolveThemeObject';
21
16
  export * from './resolveThemeInfo';
22
17
  export * from './resolveThemeLayouts';
package/lib/app/index.js CHANGED
@@ -21,7 +21,6 @@ __exportStar(require("./appUse"), exports);
21
21
  __exportStar(require("./createBaseApp"), exports);
22
22
  __exportStar(require("./createBuildApp"), exports);
23
23
  __exportStar(require("./createDevApp"), exports);
24
- __exportStar(require("./normalizePluginConfig"), exports);
25
24
  __exportStar(require("./resolveAppDir"), exports);
26
25
  __exportStar(require("./resolveAppEnv"), exports);
27
26
  __exportStar(require("./resolveAppOptions"), exports);
@@ -29,10 +28,6 @@ __exportStar(require("./resolveAppPages"), exports);
29
28
  __exportStar(require("./resolveAppSiteData"), exports);
30
29
  __exportStar(require("./resolveAppVersion"), exports);
31
30
  __exportStar(require("./resolveAppWriteTemp"), exports);
32
- __exportStar(require("./resolveBundler"), exports);
33
31
  __exportStar(require("./resolvePluginObject"), exports);
34
- __exportStar(require("./resolvePluginModule"), exports);
35
- __exportStar(require("./resolvePluginsFromConfig"), exports);
36
- __exportStar(require("./resolveThemeObject"), exports);
37
32
  __exportStar(require("./resolveThemeInfo"), exports);
38
33
  __exportStar(require("./resolveThemeLayouts"), exports);
@@ -2,48 +2,47 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.preparePagesRoutes = void 0;
4
4
  const shared_1 = require("@vuepress/shared");
5
+ /**
6
+ * Transform a page object to a route item
7
+ */
8
+ const transformPageToRouteItem = ({ key, path, pathInferred, filePathRelative, routeMeta, }) => {
9
+ // paths that should redirect to this page, use set to dedupe
10
+ const redirectsSet = new Set();
11
+ // redirect from decoded path
12
+ redirectsSet.add(decodeURI(path));
13
+ if (path.endsWith('/')) {
14
+ // redirect from index path
15
+ redirectsSet.add(path + 'index.html');
16
+ }
17
+ else {
18
+ // redirect from the path that does not end with `.html`
19
+ redirectsSet.add(path.replace(/.html$/, ''));
20
+ }
21
+ // redirect from inferred path
22
+ if (pathInferred !== null) {
23
+ redirectsSet.add(pathInferred);
24
+ redirectsSet.add(encodeURI(pathInferred));
25
+ }
26
+ // redirect from filename path
27
+ if (filePathRelative !== null) {
28
+ const filenamePath = (0, shared_1.ensureLeadingSlash)(filePathRelative);
29
+ redirectsSet.add(filenamePath);
30
+ redirectsSet.add(encodeURI(filenamePath));
31
+ }
32
+ // avoid redirect from the page path itself
33
+ redirectsSet.delete(path);
34
+ return [key, path, routeMeta, [...redirectsSet]];
35
+ };
5
36
  /**
6
37
  * Generate routes temp file
7
38
  */
8
39
  const preparePagesRoutes = async (app) => {
40
+ const routeItems = app.pages.map(transformPageToRouteItem);
9
41
  const content = `\
10
- import { Vuepress } from '@vuepress/client/lib/components/Vuepress'
42
+ import { Vuepress } from '@vuepress/client'
11
43
 
12
44
  const routeItems = [\
13
- ${app.pages
14
- .map(({ key, path, pathInferred, filePathRelative, routeMeta }) => {
15
- const redirects = [];
16
- const routeItem = [key, path, routeMeta, redirects];
17
- // paths that should redirect to this page
18
- const redirectsSet = new Set();
19
- // redirect from decoded path
20
- redirectsSet.add(decodeURI(path));
21
- if (path.endsWith('/')) {
22
- // redirect from index path
23
- redirectsSet.add(path + 'index.html');
24
- }
25
- else {
26
- // redirect from the path that does not end with `.html`
27
- redirectsSet.add(path.replace(/.html$/, ''));
28
- }
29
- // redirect from inferred path
30
- if (pathInferred !== null) {
31
- redirectsSet.add(pathInferred);
32
- redirectsSet.add(encodeURI(pathInferred));
33
- }
34
- // redirect from filename path
35
- if (filePathRelative !== null) {
36
- const filenamePath = (0, shared_1.ensureLeadingSlash)(filePathRelative);
37
- redirectsSet.add(filenamePath);
38
- redirectsSet.add(encodeURI(filenamePath));
39
- }
40
- // avoid redirect from the page path itself
41
- redirectsSet.delete(path);
42
- // add redirects to route item
43
- redirects.push(...redirectsSet);
44
- return `\n ${JSON.stringify(routeItem)},`;
45
- })
46
- .join('')}
45
+ ${routeItems.map((routeItem) => `\n ${JSON.stringify(routeItem)},`).join('')}
47
46
  ]
48
47
 
49
48
  export const pagesRoutes = routeItems.reduce(
@@ -64,8 +63,8 @@ export const pagesRoutes = routeItems.reduce(
64
63
  },
65
64
  [
66
65
  {
67
- name: "404",
68
- path: "/:catchAll(.*)",
66
+ name: '404',
67
+ path: '/:catchAll(.*)',
69
68
  component: Vuepress,
70
69
  }
71
70
  ]
@@ -2,4 +2,4 @@ import type { AppConfig, AppOptions } from '../types';
2
2
  /**
3
3
  * Create app options with default values
4
4
  */
5
- export declare const resolveAppOptions: ({ base, lang, title, description, head, locales, theme, themeConfig, bundler, bundlerConfig, source, dest, temp, cache, public: publicDir, markdown, host, port, debug, open, pagePatterns, templateDev, templateBuild, shouldPreload, shouldPrefetch, plugins, }: AppConfig) => AppOptions;
5
+ export declare const resolveAppOptions: ({ base, lang, title, description, head, locales, source, dest, temp, cache, public: publicDir, host, port, open, templateDev, shouldPreload, shouldPrefetch, templateBuild, bundler, debug, markdown, pagePatterns, plugins, theme, }: AppConfig) => AppOptions;
@@ -8,43 +8,37 @@ const utils_1 = require("@vuepress/utils");
8
8
  const resolveAppOptions = ({
9
9
  // site config
10
10
  base = '/', lang = 'en-US', title = '', description = '', head = [], locales = {},
11
- // theme config
12
- theme = '@vuepress/theme-default', themeConfig = {},
13
- // bundler config
14
- bundler = '@vuepress/bundler-vite', bundlerConfig = {},
15
11
  // directory config
16
12
  source, dest = utils_1.path.resolve(source, '.vuepress/dist'), temp = utils_1.path.resolve(source, '.vuepress/.temp'), cache = utils_1.path.resolve(source, '.vuepress/.cache'), public: publicDir = utils_1.path.resolve(source, '.vuepress/public'),
17
- // markdown config
18
- markdown = {},
19
- // development config
20
- host = '0.0.0.0', port = 8080, debug = false, open = false, pagePatterns = ['**/*.md', '!.vuepress', '!node_modules'], templateDev = utils_1.path.normalize(require.resolve('@vuepress/client/templates/index.dev.html')), templateBuild = utils_1.path.normalize(require.resolve('@vuepress/client/templates/index.build.html')), shouldPreload = true, shouldPrefetch = false,
21
- // plugin config
22
- plugins = [], }) => ({
13
+ // dev config
14
+ host = '0.0.0.0', port = 8080, open = false, templateDev = utils_1.path.normalize(require.resolve('@vuepress/client/templates/dev.html')),
15
+ // build config
16
+ shouldPreload = true, shouldPrefetch = true, templateBuild = utils_1.path.normalize(require.resolve('@vuepress/client/templates/build.html')),
17
+ // common config
18
+ bundler, debug = false, markdown = {}, pagePatterns = ['**/*.md', '!.vuepress', '!node_modules'], plugins = [], theme, }) => ({
23
19
  base,
24
20
  lang,
25
21
  title,
26
22
  description,
27
23
  head,
28
24
  locales,
29
- theme,
30
- themeConfig,
31
- bundler,
32
- bundlerConfig,
33
25
  source,
34
26
  dest,
35
27
  temp,
36
28
  cache,
37
29
  public: publicDir,
38
- markdown,
39
- debug,
40
30
  host,
41
31
  port,
42
32
  open,
43
- pagePatterns,
44
33
  templateDev,
45
- templateBuild,
46
34
  shouldPreload,
47
35
  shouldPrefetch,
36
+ templateBuild,
37
+ bundler,
38
+ debug,
39
+ markdown,
40
+ pagePatterns,
48
41
  plugins,
42
+ theme,
49
43
  });
50
44
  exports.resolveAppOptions = resolveAppOptions;
@@ -1,5 +1,5 @@
1
- import type { App, Plugin, PluginObject, PluginOptions } from '../types';
1
+ import type { App, Plugin, PluginObject } from '../types';
2
2
  /**
3
3
  * Resolve a plugin object according to name / path / module and config
4
4
  */
5
- export declare const resolvePluginObject: <T extends PluginOptions = PluginOptions, U extends PluginObject = PluginObject>(app: App, plugin: string | Plugin<T, U>, pluginConfig?: Partial<T>) => U;
5
+ export declare const resolvePluginObject: <T extends PluginObject = PluginObject>(app: App, plugin: Plugin<T>) => T;
@@ -2,21 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePluginObject = void 0;
4
4
  const shared_1 = require("@vuepress/shared");
5
- const utils_1 = require("@vuepress/utils");
6
- const resolvePluginModule_1 = require("./resolvePluginModule");
7
5
  /**
8
6
  * Resolve a plugin object according to name / path / module and config
9
7
  */
10
- const resolvePluginObject = (app, plugin, pluginConfig = {}) => {
11
- const pluginModule = (0, shared_1.isString)(plugin)
12
- ? (0, resolvePluginModule_1.resolvePluginModule)(plugin)
13
- : plugin;
14
- if (pluginModule === null) {
15
- throw utils_1.logger.createError(`plugin is not found: ${utils_1.chalk.magenta(plugin)}`);
16
- }
17
- const pluginObject = (0, shared_1.isFunction)(pluginModule)
18
- ? pluginModule(pluginConfig, app)
19
- : pluginModule;
20
- return pluginObject;
21
- };
8
+ const resolvePluginObject = (app, plugin) => ((0, shared_1.isFunction)(plugin) ? plugin(app) : plugin);
22
9
  exports.resolvePluginObject = resolvePluginObject;
@@ -1,5 +1,5 @@
1
- import type { App, ThemeConfig, ThemeInfo } from '../types';
1
+ import type { App, Theme, ThemeInfo } from '../types';
2
2
  /**
3
3
  * Resolve theme info and its parent theme info
4
4
  */
5
- export declare const resolveThemeInfo: (app: App, theme: string, themeConfig: ThemeConfig) => ThemeInfo;
5
+ export declare const resolveThemeInfo: (app: App, theme: Theme) => ThemeInfo;
@@ -1,22 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveThemeInfo = void 0;
4
- const resolvePluginsFromConfig_1 = require("./resolvePluginsFromConfig");
4
+ const resolvePluginObject_1 = require("./resolvePluginObject");
5
5
  const resolveThemeLayouts_1 = require("./resolveThemeLayouts");
6
- const resolveThemeObject_1 = require("./resolveThemeObject");
7
6
  /**
8
7
  * Resolve theme info and its parent theme info
9
8
  */
10
- const resolveThemeInfo = (app, theme, themeConfig) => {
11
- var _a, _b;
9
+ const resolveThemeInfo = (app, theme) => {
10
+ var _a, _b, _c;
12
11
  // resolve current theme info
13
- const themeObject = (0, resolveThemeObject_1.resolveThemeObject)(app, theme, themeConfig);
12
+ const themeObject = (0, resolvePluginObject_1.resolvePluginObject)(app, theme);
14
13
  const themeInfo = {
15
14
  layouts: (0, resolveThemeLayouts_1.resolveThemeLayouts)(themeObject.layouts),
16
- plugins: [
17
- ...(0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, themeObject.plugins),
18
- themeObject,
19
- ],
15
+ plugins: [...((_a = themeObject.plugins) !== null && _a !== void 0 ? _a : []), themeObject],
20
16
  templateBuild: themeObject.templateBuild,
21
17
  templateDev: themeObject.templateDev,
22
18
  };
@@ -25,12 +21,12 @@ const resolveThemeInfo = (app, theme, themeConfig) => {
25
21
  return themeInfo;
26
22
  }
27
23
  // resolve parent theme info recursively
28
- const parentThemeInfo = (0, exports.resolveThemeInfo)(app, themeObject.extends, themeConfig);
24
+ const parentThemeInfo = (0, exports.resolveThemeInfo)(app, themeObject.extends);
29
25
  return {
30
26
  layouts: { ...parentThemeInfo.layouts, ...themeInfo.layouts },
31
27
  plugins: [...parentThemeInfo.plugins, ...themeInfo.plugins],
32
- templateBuild: (_a = themeObject.templateBuild) !== null && _a !== void 0 ? _a : parentThemeInfo.templateBuild,
33
- templateDev: (_b = themeObject.templateDev) !== null && _b !== void 0 ? _b : parentThemeInfo.templateDev,
28
+ templateBuild: (_b = themeObject.templateBuild) !== null && _b !== void 0 ? _b : parentThemeInfo.templateBuild,
29
+ templateDev: (_c = themeObject.templateDev) !== null && _c !== void 0 ? _c : parentThemeInfo.templateDev,
34
30
  };
35
31
  };
36
32
  exports.resolveThemeInfo = resolveThemeInfo;
@@ -0,0 +1,5 @@
1
+ import type { App, AppConfig } from '../types';
2
+ /**
3
+ * Setup theme and plugins for vuepress app
4
+ */
5
+ export declare const setupAppThemeAndPlugins: (app: App, config: AppConfig) => void;
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupAppTheme = void 0;
3
+ exports.setupAppThemeAndPlugins = void 0;
4
4
  const resolveThemeInfo_1 = require("./resolveThemeInfo");
5
5
  /**
6
- * Setup theme for vuepress app
6
+ * Setup theme and plugins for vuepress app
7
7
  */
8
- const setupAppTheme = (app, config) => {
8
+ const setupAppThemeAndPlugins = (app, config) => {
9
9
  var _a, _b, _c, _d;
10
10
  // recursively resolve theme info
11
- const themeInfo = (0, resolveThemeInfo_1.resolveThemeInfo)(app, app.options.theme, app.options.themeConfig);
11
+ const themeInfo = (0, resolveThemeInfo_1.resolveThemeInfo)(app, app.options.theme);
12
12
  // set up app layouts and templates
13
13
  app.layouts = themeInfo.layouts;
14
14
  app.options.templateDev =
15
15
  (_b = (_a = config.templateDev) !== null && _a !== void 0 ? _a : themeInfo.templateDev) !== null && _b !== void 0 ? _b : app.options.templateDev;
16
16
  app.options.templateBuild =
17
17
  (_d = (_c = config.templateBuild) !== null && _c !== void 0 ? _c : themeInfo.templateBuild) !== null && _d !== void 0 ? _d : app.options.templateBuild;
18
- // use theme plugins
19
- themeInfo.plugins.forEach((plugin) => app.use(plugin));
18
+ [...themeInfo.plugins, ...app.options.plugins]
19
+ .flat()
20
+ .forEach((plugin) => app.use(plugin));
20
21
  };
21
- exports.setupAppTheme = setupAppTheme;
22
+ exports.setupAppThemeAndPlugins = setupAppThemeAndPlugins;
@@ -80,7 +80,6 @@ const createPage = async (app, options) => {
80
80
  // resolve page component and extract headers & links
81
81
  const { componentFilePath, componentFilePathRelative, componentFileChunkName, } = await (0, resolvePageComponentInfo_1.resolvePageComponentInfo)({
82
82
  app,
83
- hoistedTags,
84
83
  htmlFilePathRelative,
85
84
  key,
86
85
  });
@@ -2,9 +2,8 @@ import type { App } from '../types';
2
2
  /**
3
3
  * Resolve page component and related info
4
4
  */
5
- export declare const resolvePageComponentInfo: ({ app, hoistedTags, htmlFilePathRelative, key, }: {
5
+ export declare const resolvePageComponentInfo: ({ app, htmlFilePathRelative, key, }: {
6
6
  app: App;
7
- hoistedTags: string[];
8
7
  htmlFilePathRelative: string;
9
8
  key: string;
10
9
  }) => Promise<{
@@ -5,7 +5,7 @@ const utils_1 = require("@vuepress/utils");
5
5
  /**
6
6
  * Resolve page component and related info
7
7
  */
8
- const resolvePageComponentInfo = async ({ app, hoistedTags, htmlFilePathRelative, key, }) => {
8
+ const resolvePageComponentInfo = async ({ app, htmlFilePathRelative, key, }) => {
9
9
  // resolve component file path
10
10
  const componentFilePathRelative = utils_1.path.join('pages', `${htmlFilePathRelative}.vue`);
11
11
  const componentFilePath = app.dir.temp(componentFilePathRelative);
@@ -1,8 +1,8 @@
1
1
  import type { Markdown } from '@vuepress/markdown';
2
2
  import type { SiteData } from '@vuepress/shared';
3
- import type { BundlerBuild, BundlerDev } from '../bundler';
3
+ import type { Bundler } from '../bundler';
4
4
  import type { Page } from '../page';
5
- import type { Plugin, PluginOptions } from '../plugin';
5
+ import type { Plugin } from '../plugin';
6
6
  import type { PluginApi } from '../pluginApi';
7
7
  import type { AppOptions } from './options';
8
8
  import type { AppDir, AppEnv, AppWriteTemp } from './utils';
@@ -41,7 +41,7 @@ export interface App {
41
41
  /**
42
42
  * Use a plugin
43
43
  */
44
- use: <T extends PluginOptions>(plugin: Plugin<T> | string, config?: Partial<T>) => this;
44
+ use: (plugin: Plugin) => this;
45
45
  /**
46
46
  * Initialize app.
47
47
  *
@@ -83,7 +83,7 @@ export interface DevApp extends App {
83
83
  *
84
84
  * Should be called after `app.prepare()`.
85
85
  */
86
- dev: () => ReturnType<BundlerDev>;
86
+ dev: () => ReturnType<Bundler['dev']>;
87
87
  }
88
88
  /**
89
89
  * Vuepress build app
@@ -94,5 +94,5 @@ export interface BuildApp extends App {
94
94
  *
95
95
  * Should be called after `app.prepare()`.
96
96
  */
97
- build: () => ReturnType<BundlerBuild>;
97
+ build: () => ReturnType<Bundler['build']>;
98
98
  }
@@ -1,44 +1,83 @@
1
1
  import type { MarkdownOptions } from '@vuepress/markdown';
2
2
  import type { SiteData } from '@vuepress/shared';
3
- import type { BundlerConfig } from '../bundler';
3
+ import type { Bundler } from '../bundler';
4
4
  import type { PluginConfig } from '../plugin';
5
- import type { ThemeConfig } from '../theme';
5
+ import type { Theme } from '../theme';
6
6
  /**
7
- * Config to create vuepress app
7
+ * Vuepress app common config that shared between dev and build
8
8
  */
9
- export declare type AppConfig<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> = Partial<SiteData> & AppConfigDev & AppConfigBuild & {
10
- theme?: string;
11
- themeConfig?: Partial<T>;
12
- bundler?: string;
13
- bundlerConfig?: Partial<U>;
9
+ export interface AppConfigCommon extends Partial<SiteData> {
14
10
  source: string;
15
11
  dest?: string;
16
12
  temp?: string;
17
13
  cache?: string;
18
14
  public?: string;
19
15
  debug?: boolean;
20
- pagePatterns?: string[];
21
16
  markdown?: MarkdownOptions;
22
- plugins?: PluginConfig[];
23
- };
17
+ pagePatterns?: string[];
18
+ bundler: Bundler;
19
+ theme: Theme;
20
+ plugins?: PluginConfig;
21
+ }
24
22
  /**
25
23
  * Vuepress app config for dev
26
24
  */
27
25
  export interface AppConfigDev {
26
+ /**
27
+ * Specify the host to use for the dev server
28
+ *
29
+ * @default '0.0.0.0'
30
+ */
28
31
  host?: string;
32
+ /**
33
+ * Specify the port to use for the dev server
34
+ *
35
+ * @default 8080
36
+ */
29
37
  port?: number;
38
+ /**
39
+ * Whether to open the browser after dev-server had been started
40
+ *
41
+ * @default false
42
+ */
30
43
  open?: boolean;
44
+ /**
45
+ * Specify the path of the HTML template to be used for dev
46
+ *
47
+ * @default '@vuepress/client/templates/dev.html'
48
+ */
31
49
  templateDev?: string;
32
50
  }
33
51
  /**
34
52
  * Vuepress app config for build
35
53
  */
36
54
  export interface AppConfigBuild {
55
+ /**
56
+ * Determine what resource files should be preloaded. Use boolean value to
57
+ * totally enable / disable.
58
+ *
59
+ * @default true
60
+ */
37
61
  shouldPreload?: ((file: string, type: string) => boolean) | boolean;
62
+ /**
63
+ * Determine what resource files should be prefetched. Use boolean value to
64
+ * totally enable / disable.
65
+ *
66
+ * @default false
67
+ */
38
68
  shouldPrefetch?: ((file: string, type: string) => boolean) | boolean;
69
+ /**
70
+ * Specify the path of the HTML template to be used for build
71
+ *
72
+ * @default '@vuepress/client/templates/build.html'
73
+ */
39
74
  templateBuild?: string;
40
75
  }
76
+ /**
77
+ * Vuepress app config
78
+ */
79
+ export declare type AppConfig = AppConfigCommon & AppConfigDev & AppConfigBuild;
41
80
  /**
42
81
  * Vuepress app options
43
82
  */
44
- export declare type AppOptions<T extends ThemeConfig = ThemeConfig, U extends BundlerConfig = BundlerConfig> = Required<AppConfig<T, U>>;
83
+ export declare type AppOptions = Required<AppConfig>;
@@ -7,28 +7,7 @@ import type { App } from './app';
7
7
  * - build: bundle assets for deployment
8
8
  */
9
9
  export interface Bundler {
10
- dev: BundlerDev;
11
- build: BundlerBuild;
12
- }
13
- export declare type BundlerDev = (app: App) => Promise<() => Promise<void>>;
14
- export declare type BundlerBuild = (app: App) => Promise<void>;
15
- /**
16
- * A function that returns a bundler instance
17
- *
18
- * A bundler package should have a `CreateBundlerFunction` as the default export
19
- */
20
- export declare type CreateBundlerFunction<BundlerOptions extends BundlerConfig = Partial<BundlerConfig>> = (options: BundlerOptions) => Bundler;
21
- /**
22
- * Bundler entry type
23
- */
24
- export interface BundlerEntry {
25
- createBundler: CreateBundlerFunction;
26
- }
27
- /**
28
- * User config type of bundler
29
- *
30
- * @remark suffix `Config` means this is for user config
31
- */
32
- export interface BundlerConfig {
33
- [key: string]: any;
10
+ name: string;
11
+ dev: (app: App) => Promise<() => Promise<void>>;
12
+ build: (app: App) => Promise<void>;
34
13
  }
@@ -9,13 +9,13 @@ import type { HooksExposed } from './pluginApi';
9
9
  *
10
10
  * A plugin package should have a `Plugin` as the default export
11
11
  */
12
- export declare type Plugin<T extends PluginOptions = PluginOptions, U extends PluginObject = PluginObject> = U | PluginFunction<T, U>;
12
+ export declare type Plugin<T extends PluginObject = PluginObject> = T | PluginFunction<T>;
13
13
  /**
14
14
  * Vuepress plugin function
15
15
  *
16
16
  * It accepts plugin options and vuepress app, returns plugin object
17
17
  */
18
- export declare type PluginFunction<T extends PluginOptions = PluginOptions, U extends PluginObject = PluginObject> = (pluginConfig: Partial<T>, app: App) => U;
18
+ export declare type PluginFunction<T extends PluginObject = PluginObject> = (app: App) => T;
19
19
  /**
20
20
  * Vuepress plugin object
21
21
  */
@@ -24,22 +24,6 @@ export interface PluginObject extends Partial<HooksExposed> {
24
24
  multiple?: boolean;
25
25
  }
26
26
  /**
27
- * Vuepress plugin options basic type
27
+ * Config field for plugins
28
28
  */
29
- export declare type PluginOptions = Record<string, any>;
30
- /**
31
- * Plugin config to be used in user config file
32
- *
33
- * Users can use this config to control which plugins to be used,
34
- * and set the plugin options
35
- *
36
- * @remark suffix `Config` means this is for user config
37
- */
38
- export declare type PluginConfig<T extends PluginOptions = PluginOptions> = string | Plugin<T> | [string | Plugin<T>] | [string | Plugin<T>, Partial<T> | boolean];
39
- /**
40
- * Normalized plugin config
41
- */
42
- export declare type PluginConfigNormalized<T extends PluginOptions = PluginOptions> = [
43
- Plugin<T> | string,
44
- Partial<T> | boolean
45
- ];
29
+ export declare type PluginConfig = (Plugin | Plugin[])[];
@@ -8,23 +8,19 @@ import type { Plugin, PluginConfig, PluginFunction, PluginObject } from './plugi
8
8
  *
9
9
  * A theme package should have a `Theme` as the default export
10
10
  */
11
- export declare type Theme<T extends ThemeConfig = ThemeConfig> = Plugin<T, ThemeObject>;
11
+ export declare type Theme = Plugin<ThemeObject>;
12
12
  /**
13
13
  * Vuepress theme function
14
14
  */
15
- export declare type ThemeFunction<T extends ThemeConfig = ThemeConfig> = PluginFunction<T, ThemeObject>;
15
+ export declare type ThemeFunction = PluginFunction<ThemeObject>;
16
16
  /**
17
17
  * Vuepress theme object
18
18
  */
19
- export interface ThemeObject extends PluginObject {
20
- /**
21
- * Theme plugin should never be multiple
22
- */
23
- multiple?: false;
19
+ export interface ThemeObject extends Omit<PluginObject, 'multiple'> {
24
20
  /**
25
21
  * Extended parent theme
26
22
  */
27
- extends?: string;
23
+ extends?: Theme;
28
24
  /**
29
25
  * Specify the layouts directory or components map
30
26
  */
@@ -32,7 +28,7 @@ export interface ThemeObject extends PluginObject {
32
28
  /**
33
29
  * Allow using plugins in theme
34
30
  */
35
- plugins?: PluginConfig[];
31
+ plugins?: PluginConfig;
36
32
  /**
37
33
  * Allow overriding default templateBuild
38
34
  */
@@ -42,16 +38,6 @@ export interface ThemeObject extends PluginObject {
42
38
  */
43
39
  templateDev?: string;
44
40
  }
45
- /**
46
- * Theme config to be used in user config file
47
- *
48
- * It will be used by a theme itself, but not by vuepress.
49
- *
50
- * Vuepress will only transfer this config to theme
51
- *
52
- * @remark suffix `Config` means this is for user config
53
- */
54
- export declare type ThemeConfig = Record<string, any>;
55
41
  /**
56
42
  * Resolved theme info
57
43
  */
@@ -63,7 +49,7 @@ export interface ThemeInfo {
63
49
  /**
64
50
  * Plugins, including theme itself and plugins used by theme
65
51
  */
66
- plugins: PluginObject[];
52
+ plugins: PluginConfig;
67
53
  /**
68
54
  * Default build template
69
55
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/core",
3
- "version": "2.0.0-beta.38",
3
+ "version": "2.0.0-beta.41",
4
4
  "description": "Core package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -15,26 +15,29 @@
15
15
  "url": "git+https://github.com/vuepress/vuepress-next.git"
16
16
  },
17
17
  "license": "MIT",
18
- "author": "Evan You",
18
+ "author": "meteorlxy",
19
19
  "main": "lib/index.js",
20
20
  "types": "lib/index.d.ts",
21
21
  "files": [
22
22
  "lib"
23
23
  ],
24
- "scripts": {
25
- "build": "tsc -b tsconfig.build.json",
26
- "clean": "rimraf lib *.tsbuildinfo"
27
- },
28
24
  "dependencies": {
29
- "@vuepress/client": "2.0.0-beta.38",
30
- "@vuepress/markdown": "2.0.0-beta.38",
31
- "@vuepress/shared": "2.0.0-beta.38",
32
- "@vuepress/utils": "2.0.0-beta.38",
25
+ "@vuepress/client": "2.0.0-beta.41",
26
+ "@vuepress/markdown": "2.0.0-beta.41",
27
+ "@vuepress/shared": "2.0.0-beta.41",
28
+ "@vuepress/utils": "2.0.0-beta.41",
33
29
  "gray-matter": "^4.0.3",
34
- "toml": "^3.0.0"
30
+ "toml": "^3.0.0",
31
+ "vue": "^3.2.33"
32
+ },
33
+ "peerDependencies": {
34
+ "vue": "^3.2.33"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "7cb24eab18628a66371a367090f7c9c33b519136"
40
- }
39
+ "scripts": {
40
+ "build": "tsc -b tsconfig.build.json",
41
+ "clean": "rimraf lib *.tsbuildinfo"
42
+ }
43
+ }
@@ -1,2 +0,0 @@
1
- import type { PluginConfig, PluginConfigNormalized, PluginOptions } from '../types';
2
- export declare const normalizePluginConfig: <T extends PluginOptions>(pluginConfig: PluginConfig<T>) => PluginConfigNormalized<T>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizePluginConfig = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
- const normalizePluginConfig = (pluginConfig) => {
6
- var _a;
7
- // ['container'] -> ['container', true]
8
- // ['container', options] -> ['container', options]
9
- if ((0, shared_1.isArray)(pluginConfig)) {
10
- return [pluginConfig[0], (_a = pluginConfig[1]) !== null && _a !== void 0 ? _a : true];
11
- }
12
- // 'container' -> ['container', true]
13
- return [pluginConfig, true];
14
- };
15
- exports.normalizePluginConfig = normalizePluginConfig;
@@ -1,2 +0,0 @@
1
- import type { AppOptions, Bundler } from '../types';
2
- export declare const resolveBundler: ({ bundler, bundlerConfig, }: AppOptions) => Bundler;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveBundler = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
- const resolveBundler = ({ bundler, bundlerConfig, }) => {
6
- const bundlerPackage = (0, shared_1.normalizePackageName)(bundler, 'vuepress', 'bundler');
7
- const { createBundler } = require(bundlerPackage);
8
- return createBundler(bundlerConfig);
9
- };
10
- exports.resolveBundler = resolveBundler;
@@ -1,5 +0,0 @@
1
- import type { Plugin, PluginObject, PluginOptions } from '../types';
2
- /**
3
- * Resolve the module of a plugin according to name or path
4
- */
5
- export declare const resolvePluginModule: <T extends PluginOptions = PluginOptions, U extends PluginObject = PluginObject>(pluginName: string) => Plugin<T, U> | null;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolvePluginModule = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
- const utils_1 = require("@vuepress/utils");
6
- /**
7
- * Resolve the module of a plugin according to name or path
8
- */
9
- const resolvePluginModule = (pluginName) => {
10
- const pluginEntry = utils_1.path.isAbsolute(pluginName)
11
- ? pluginName
12
- : (0, utils_1.requireResolve)((0, shared_1.normalizePackageName)(pluginName, 'vuepress', 'plugin'));
13
- if (pluginEntry === null) {
14
- return null;
15
- }
16
- const pluginModule = require(pluginEntry);
17
- // allow default export
18
- return (0, utils_1.hasExportDefault)(pluginModule) ? pluginModule.default : pluginModule;
19
- };
20
- exports.resolvePluginModule = resolvePluginModule;
@@ -1,5 +0,0 @@
1
- import type { App, PluginConfig, PluginObject } from '../types';
2
- /**
3
- * Resolve plugin objects from plugin config array
4
- */
5
- export declare const resolvePluginsFromConfig: (app: App, plugins?: PluginConfig[]) => PluginObject[];
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolvePluginsFromConfig = void 0;
4
- const normalizePluginConfig_1 = require("./normalizePluginConfig");
5
- const resolvePluginObject_1 = require("./resolvePluginObject");
6
- /**
7
- * Resolve plugin objects from plugin config array
8
- */
9
- const resolvePluginsFromConfig = (app, plugins = []) => plugins.reduce((prev, item) => {
10
- const [plugin, config] = (0, normalizePluginConfig_1.normalizePluginConfig)(item);
11
- if (config !== false) {
12
- prev.push((0, resolvePluginObject_1.resolvePluginObject)(app, plugin, config === true ? {} : config));
13
- }
14
- return prev;
15
- }, []);
16
- exports.resolvePluginsFromConfig = resolvePluginsFromConfig;
@@ -1,5 +0,0 @@
1
- import type { App, ThemeConfig, ThemeObject } from '../types';
2
- /**
3
- * Resolve a theme object according to the theme name
4
- */
5
- export declare const resolveThemeObject: (app: App, theme: string, themeConfig: ThemeConfig) => ThemeObject;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveThemeObject = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
- const utils_1 = require("@vuepress/utils");
6
- const resolvePluginObject_1 = require("./resolvePluginObject");
7
- /**
8
- * Resolve a theme object according to the theme name
9
- */
10
- const resolveThemeObject = (app, theme, themeConfig) => {
11
- // resolve theme entry according to theme name
12
- const themeEntry = (0, utils_1.requireResolve)(utils_1.path.isAbsolute(theme)
13
- ? theme
14
- : (0, shared_1.normalizePackageName)(theme, 'vuepress', 'theme'));
15
- if (themeEntry === null) {
16
- throw utils_1.logger.createError(`theme is not found: ${utils_1.chalk.magenta(theme)}`);
17
- }
18
- // resolve theme object from theme entry
19
- const themeObject = (0, resolvePluginObject_1.resolvePluginObject)(app, themeEntry, themeConfig);
20
- return themeObject;
21
- };
22
- exports.resolveThemeObject = resolveThemeObject;
@@ -1,5 +0,0 @@
1
- import type { App } from '../types';
2
- /**
3
- * Setup plugins for vuepress app
4
- */
5
- export declare const setupAppPlugins: (app: App) => void;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupAppPlugins = void 0;
4
- const resolvePluginsFromConfig_1 = require("./resolvePluginsFromConfig");
5
- /**
6
- * Setup plugins for vuepress app
7
- */
8
- const setupAppPlugins = (app) => {
9
- // resolve plugins from options
10
- const plugins = (0, resolvePluginsFromConfig_1.resolvePluginsFromConfig)(app, app.options.plugins);
11
- // use plugins
12
- plugins.forEach((plugin) => app.use(plugin));
13
- };
14
- exports.setupAppPlugins = setupAppPlugins;
@@ -1,5 +0,0 @@
1
- import type { App, AppConfig } from '../types';
2
- /**
3
- * Setup theme for vuepress app
4
- */
5
- export declare const setupAppTheme: (app: App, config: AppConfig) => void;