Skip to content

Commit

Permalink
chore: make all example executor async (#75)
Browse files Browse the repository at this point in the history
Co-authored-by: brightwwu <[email protected]>
  • Loading branch information
wre232114 and brightwwu authored Apr 8, 2024
1 parent 93bad20 commit ba582f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions docs/api/js-plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function MyPlugin(options: PluginOptions): JsPlugin {
filters: {
resolvedPaths: ['\\.test$'] // filter files to improve performance
},
executor({ resolvedPath }) {
async executor({ resolvedPath }) {
if (test && resolvedPath.endsWith('.test')) {
return {
content: 'test file',
Expand Down Expand Up @@ -151,7 +151,7 @@ const myPlugin = () => {
filters: {
moduleTypes: ['js']
},
executor(param) {
async executor(param) {
if (farmConfig.xxx) {
// ...
}
Expand Down Expand Up @@ -227,7 +227,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
buildStart: {
executor() {
async executor() {
// set up my plugin before compilation.
myPluginContext.setup();
}
Expand Down Expand Up @@ -526,7 +526,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
buildEnd: {
executor() {
async executor() {
// update my plugin status
myPluginContext.updateStatus('module-graph-built');
}
Expand Down Expand Up @@ -554,7 +554,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
renderStart: {
executor() {
async executor() {
// update my plugin status
myPluginContext.updateStatus('render-start');
}
Expand Down Expand Up @@ -736,7 +736,7 @@ Transform the final generated html(after all `<script>`, `<link>` tag are inject
const myPlugin = () => ({
name: 'my-plugin',
transformHtml: {
executor({ htmlResource }) {
async executor({ htmlResource }) {
const htmlCode = Buffer.from(htmlResource).toString();

const newHtmlCode = htmlCode.replace('my-app-data', data);
Expand Down Expand Up @@ -786,7 +786,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
pluginCacheLoaded: {
executor(bytes) {
async executor(bytes) {
const str = Buffer.from(bytes).toString();
cachedData = JSON.parse(str);
}
Expand Down Expand Up @@ -818,7 +818,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
writePluginCache: {
executor() {
async executor() {
const bytes = [...Buffer.from(JSON.stringify(data))];
return bytes;
}
Expand Down Expand Up @@ -847,7 +847,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
finish: {
executor() {
async executor() {
// update my plugin status
myPluginContext.updateStatus('finish');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function MyPlugin(options: PluginOptions): JsPlugin {
filters: {
resolvedPaths: ['\\.test$'] // 过滤文件以提高性能
},
executor({ resolvedPath }) {
async executor({ resolvedPath }) {
if (test && resolvedPath.endsWith('.test')) {
return {
content: 'test file',
Expand Down Expand Up @@ -150,7 +150,7 @@ const myPlugin = () => {
filters: {
moduleTypes: ['js']
},
executor(param) {
async executor(param) {
if (farmConfig.xxx) {
// ...
}
Expand Down Expand Up @@ -226,7 +226,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
buildStart: {
executor() {
async executor() {
// 在编译之前初始化插件上下文
myPluginContext.setup();
}
Expand Down Expand Up @@ -523,7 +523,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
buildEnd: {
executor() {
async executor() {
// 更新插件状态
myPluginContext.updateStatus('module-graph-built');
}
Expand Down Expand Up @@ -551,7 +551,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
renderStart: {
executor() {
async executor() {
// 更新插件状态
myPluginContext.updateStatus('render-start');
}
Expand Down Expand Up @@ -732,7 +732,7 @@ type TransformHtmlHook = {
const myPlugin = () => ({
name: 'my-plugin',
transformHtml: {
executor({ htmlResource }) {
async executor({ htmlResource }) {
const htmlCode = Buffer.from(htmlResource).toString();

const newHtmlCode = htmlCode.replace('my-app-data', data);
Expand Down Expand Up @@ -782,7 +782,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
pluginCacheLoaded: {
executor(bytes) {
async executor(bytes) {
const str = Buffer.from(bytes).toString();
cachedData = JSON.parse(str);
}
Expand Down Expand Up @@ -814,7 +814,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
writePluginCache: {
executor() {
async executor() {
const bytes = [...Buffer.from(JSON.stringify(data))];
return bytes;
}
Expand Down Expand Up @@ -843,7 +843,7 @@ const myPlugin = () => {
return {
name: 'my-plugin',
finish: {
executor() {
async executor() {
// 更新插件的状态
myPluginContext.updateStatus('finish');
}
Expand Down

0 comments on commit ba582f5

Please sign in to comment.