@tarojs/service 3.3.12 → 3.4.0-beta.0
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.
- package/dist/Kernel.d.ts +2 -2
- package/dist/Kernel.js +7 -6
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +18 -4
- package/dist/utils/types.d.ts +1 -0
- package/package.json +9 -9
- package/src/Kernel.ts +10 -8
- package/src/utils/index.ts +19 -8
- package/src/utils/types.ts +2 -0
- package/types/index.d.ts +10 -1
package/dist/Kernel.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { IProjectConfig, PluginItem } from '@tarojs/taro/types/compile';
|
|
4
|
-
import { IPreset, IPlugin, IPaths, IHook, ICommand, IPlatform } from './utils/types';
|
|
4
|
+
import { IPreset, IPluginsObject, IPlugin, IPaths, IHook, ICommand, IPlatform } from './utils/types';
|
|
5
5
|
import Plugin from './Plugin';
|
|
6
6
|
import Config from './Config';
|
|
7
7
|
interface IKernelOptions {
|
|
@@ -17,7 +17,7 @@ export default class Kernel extends EventEmitter {
|
|
|
17
17
|
optsPlugins: PluginItem[] | void;
|
|
18
18
|
plugins: Map<string, IPlugin>;
|
|
19
19
|
paths: IPaths;
|
|
20
|
-
extraPlugins:
|
|
20
|
+
extraPlugins: IPluginsObject;
|
|
21
21
|
config: Config;
|
|
22
22
|
initialConfig: IProjectConfig;
|
|
23
23
|
hooks: Map<string, IHook[]>;
|
package/dist/Kernel.js
CHANGED
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const path = require("path");
|
|
13
13
|
const events_1 = require("events");
|
|
14
|
+
const lodash_1 = require("lodash");
|
|
14
15
|
const tapable_1 = require("tapable");
|
|
15
16
|
const helper_1 = require("@tarojs/helper");
|
|
16
17
|
const helper = require("@tarojs/helper");
|
|
@@ -76,7 +77,7 @@ class Kernel extends events_1.EventEmitter {
|
|
|
76
77
|
only: [...Object.keys(allConfigPresets), ...Object.keys(allConfigPlugins)]
|
|
77
78
|
});
|
|
78
79
|
this.plugins = new Map();
|
|
79
|
-
this.extraPlugins =
|
|
80
|
+
this.extraPlugins = {};
|
|
80
81
|
this.resolvePresets(allConfigPresets);
|
|
81
82
|
this.resolvePlugins(allConfigPlugins);
|
|
82
83
|
}
|
|
@@ -87,12 +88,12 @@ class Kernel extends events_1.EventEmitter {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
resolvePlugins(plugins) {
|
|
91
|
+
plugins = lodash_1.merge(this.extraPlugins, plugins);
|
|
90
92
|
const allPlugins = utils_1.resolvePresetsOrPlugins(this.appPath, plugins, constants_1.PluginType.Plugin);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.initPlugin(_plugins.shift());
|
|
93
|
+
while (allPlugins.length) {
|
|
94
|
+
this.initPlugin(allPlugins.shift());
|
|
94
95
|
}
|
|
95
|
-
this.extraPlugins =
|
|
96
|
+
this.extraPlugins = {};
|
|
96
97
|
}
|
|
97
98
|
initPreset(preset) {
|
|
98
99
|
this.debugger('initPreset', preset);
|
|
@@ -107,7 +108,7 @@ class Kernel extends events_1.EventEmitter {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
if (Array.isArray(plugins)) {
|
|
110
|
-
this.extraPlugins.
|
|
111
|
+
this.extraPlugins = lodash_1.merge(this.extraPlugins, utils_1.convertPluginsToObject(plugins)());
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
initPlugin(plugin) {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PluginItem } from '@tarojs/taro/types/compile';
|
|
2
2
|
import { PluginType } from './constants';
|
|
3
|
-
import { IPlugin } from './types';
|
|
3
|
+
import { IPluginsObject, IPlugin } from './types';
|
|
4
4
|
export declare const isNpmPkg: (name: string) => boolean;
|
|
5
5
|
export declare function getPluginPath(pluginPath: string): string;
|
|
6
|
-
export declare function convertPluginsToObject(items: PluginItem[]): () =>
|
|
7
|
-
export declare function mergePlugins(dist: PluginItem[], src: PluginItem[]): () =>
|
|
6
|
+
export declare function convertPluginsToObject(items: PluginItem[]): () => IPluginsObject;
|
|
7
|
+
export declare function mergePlugins(dist: PluginItem[], src: PluginItem[]): () => IPluginsObject;
|
|
8
8
|
export declare function resolvePresetsOrPlugins(root: string, args: any, type: PluginType): IPlugin[];
|
|
9
9
|
export declare function printHelpLog(command: any, optionsList: Map<string, string>, synopsisList?: Set<string>): void;
|
package/dist/utils/index.js
CHANGED
|
@@ -43,10 +43,24 @@ exports.mergePlugins = mergePlugins;
|
|
|
43
43
|
// getModuleDefaultExport
|
|
44
44
|
function resolvePresetsOrPlugins(root, args, type) {
|
|
45
45
|
return Object.keys(args).map(item => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
var _a;
|
|
47
|
+
let fPath;
|
|
48
|
+
try {
|
|
49
|
+
fPath = resolve.sync(item, {
|
|
50
|
+
basedir: root,
|
|
51
|
+
extensions: ['.js', '.ts']
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if ((_a = args[item]) === null || _a === void 0 ? void 0 : _a.backup) {
|
|
56
|
+
// 如果项目中没有,可以使用 CLI 中的插件
|
|
57
|
+
fPath = args[item].backup;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.log(helper_1.chalk.red(`找不到依赖 "${item}",请先在项目中安装`));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
50
64
|
return {
|
|
51
65
|
id: fPath,
|
|
52
66
|
path: fPath,
|
package/dist/utils/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/service",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.0",
|
|
4
4
|
"description": "Taro Service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"homepage": "https://github.com/NervJS/taro#readme",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@hapi/joi": "17.1.1",
|
|
37
|
-
"@tarojs/helper": "3.
|
|
38
|
-
"@tarojs/shared": "3.
|
|
39
|
-
"@tarojs/taro": "3.
|
|
40
|
-
"fs-extra": "8.1
|
|
41
|
-
"lodash": "4.17.21",
|
|
42
|
-
"resolve": "1.
|
|
43
|
-
"tapable": "1.1.3"
|
|
37
|
+
"@tarojs/helper": "3.4.0-beta.0",
|
|
38
|
+
"@tarojs/shared": "3.4.0-beta.0",
|
|
39
|
+
"@tarojs/taro": "3.4.0-beta.0",
|
|
40
|
+
"fs-extra": "^8.0.1",
|
|
41
|
+
"lodash": "^4.17.21",
|
|
42
|
+
"resolve": "^1.6.0",
|
|
43
|
+
"tapable": "^1.1.3"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "107670bc2360ee9136a0e558e6d5fad1db640fba"
|
|
46
46
|
}
|
package/src/Kernel.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from 'path'
|
|
2
2
|
import { EventEmitter } from 'events'
|
|
3
|
-
|
|
3
|
+
import { merge } from 'lodash'
|
|
4
4
|
import { AsyncSeriesWaterfallHook } from 'tapable'
|
|
5
5
|
import { IProjectConfig, PluginItem } from '@tarojs/taro/types/compile'
|
|
6
6
|
import {
|
|
@@ -14,6 +14,7 @@ import * as joi from '@hapi/joi'
|
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
16
|
IPreset,
|
|
17
|
+
IPluginsObject,
|
|
17
18
|
IPlugin,
|
|
18
19
|
IPaths,
|
|
19
20
|
IHook,
|
|
@@ -44,7 +45,7 @@ export default class Kernel extends EventEmitter {
|
|
|
44
45
|
optsPlugins: PluginItem[] | void
|
|
45
46
|
plugins: Map<string, IPlugin>
|
|
46
47
|
paths: IPaths
|
|
47
|
-
extraPlugins:
|
|
48
|
+
extraPlugins: IPluginsObject
|
|
48
49
|
config: Config
|
|
49
50
|
initialConfig: IProjectConfig
|
|
50
51
|
hooks: Map<string, IHook[]>
|
|
@@ -114,7 +115,7 @@ export default class Kernel extends EventEmitter {
|
|
|
114
115
|
only: [...Object.keys(allConfigPresets), ...Object.keys(allConfigPlugins)]
|
|
115
116
|
})
|
|
116
117
|
this.plugins = new Map()
|
|
117
|
-
this.extraPlugins =
|
|
118
|
+
this.extraPlugins = {}
|
|
118
119
|
this.resolvePresets(allConfigPresets)
|
|
119
120
|
this.resolvePlugins(allConfigPlugins)
|
|
120
121
|
}
|
|
@@ -127,12 +128,13 @@ export default class Kernel extends EventEmitter {
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
resolvePlugins (plugins) {
|
|
131
|
+
plugins = merge(this.extraPlugins, plugins)
|
|
130
132
|
const allPlugins = resolvePresetsOrPlugins(this.appPath, plugins, PluginType.Plugin)
|
|
131
|
-
|
|
132
|
-
while (
|
|
133
|
-
this.initPlugin(
|
|
133
|
+
|
|
134
|
+
while (allPlugins.length) {
|
|
135
|
+
this.initPlugin(allPlugins.shift()!)
|
|
134
136
|
}
|
|
135
|
-
this.extraPlugins =
|
|
137
|
+
this.extraPlugins = {}
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
initPreset (preset: IPreset) {
|
|
@@ -148,7 +150,7 @@ export default class Kernel extends EventEmitter {
|
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
if (Array.isArray(plugins)) {
|
|
151
|
-
this.extraPlugins
|
|
153
|
+
this.extraPlugins = merge(this.extraPlugins, convertPluginsToObject(plugins)())
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
|
package/src/utils/index.ts
CHANGED
|
@@ -2,12 +2,12 @@ import * as path from 'path'
|
|
|
2
2
|
|
|
3
3
|
import { merge } from 'lodash'
|
|
4
4
|
import * as resolve from 'resolve'
|
|
5
|
-
import { getModuleDefaultExport } from '@tarojs/helper'
|
|
5
|
+
import { getModuleDefaultExport, chalk } from '@tarojs/helper'
|
|
6
6
|
|
|
7
7
|
import { PluginItem } from '@tarojs/taro/types/compile'
|
|
8
8
|
|
|
9
9
|
import { PluginType } from './constants'
|
|
10
|
-
import { IPlugin } from './types'
|
|
10
|
+
import { IPluginsObject, IPlugin } from './types'
|
|
11
11
|
|
|
12
12
|
export const isNpmPkg: (name: string) => boolean = name => !(/^(\.|\/)/.test(name))
|
|
13
13
|
|
|
@@ -16,9 +16,9 @@ export function getPluginPath (pluginPath: string) {
|
|
|
16
16
|
throw new Error('plugin 和 preset 配置必须为绝对路径或者包名')
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function convertPluginsToObject (items: PluginItem[]) {
|
|
19
|
+
export function convertPluginsToObject (items: PluginItem[]): () => IPluginsObject {
|
|
20
20
|
return () => {
|
|
21
|
-
const obj = {}
|
|
21
|
+
const obj: IPluginsObject = {}
|
|
22
22
|
if (Array.isArray(items)) {
|
|
23
23
|
items.forEach(item => {
|
|
24
24
|
if (typeof item === 'string') {
|
|
@@ -45,10 +45,21 @@ export function mergePlugins (dist: PluginItem[], src: PluginItem[]) {
|
|
|
45
45
|
// getModuleDefaultExport
|
|
46
46
|
export function resolvePresetsOrPlugins (root: string, args, type: PluginType): IPlugin[] {
|
|
47
47
|
return Object.keys(args).map(item => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
let fPath
|
|
49
|
+
try {
|
|
50
|
+
fPath = resolve.sync(item, {
|
|
51
|
+
basedir: root,
|
|
52
|
+
extensions: ['.js', '.ts']
|
|
53
|
+
})
|
|
54
|
+
} catch (err) {
|
|
55
|
+
if (args[item]?.backup) {
|
|
56
|
+
// 如果项目中没有,可以使用 CLI 中的插件
|
|
57
|
+
fPath = args[item].backup
|
|
58
|
+
} else {
|
|
59
|
+
console.log(chalk.red(`找不到依赖 "${item}",请先在项目中安装`))
|
|
60
|
+
process.exit(1)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
52
63
|
return {
|
|
53
64
|
id: fPath,
|
|
54
65
|
path: fPath,
|
package/src/utils/types.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ export { default as Kernel } from './Kernel'
|
|
|
8
8
|
|
|
9
9
|
export { TaroPlatformBase } from './platform-plugin-base'
|
|
10
10
|
|
|
11
|
+
interface IModifyWebpackChain {
|
|
12
|
+
componentConfig?: {
|
|
13
|
+
includes: Set<string>
|
|
14
|
+
exclude: Set<string>
|
|
15
|
+
thirdPartyComponents: Map<Tagname, Attrs>
|
|
16
|
+
includeAll: boolean
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
export declare interface IPluginContext {
|
|
12
21
|
/**
|
|
13
22
|
* 获取当前所有挂载的插件
|
|
@@ -72,7 +81,7 @@ export declare interface IPluginContext {
|
|
|
72
81
|
/**
|
|
73
82
|
* 编译中修改 webpack 配置,在这个钩子中,你可以对 webpackChain 作出想要的调整,等同于配置 [`webpackChain`](./config-detail.md#miniwebpackchain)
|
|
74
83
|
*/
|
|
75
|
-
modifyWebpackChain: (fn: (args: { chain: any }) => void) => void
|
|
84
|
+
modifyWebpackChain: (fn: (args: { chain: any, webpack: any, data?: IModifyWebpackChain }) => void) => void
|
|
76
85
|
/**
|
|
77
86
|
* 修改编译后的结果
|
|
78
87
|
*/
|