Skip to content

Commit

Permalink
Merge branch 'hexojs:master' into add-event-emitter-description
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaslanjaka authored Feb 14, 2024
2 parents 36bd88a + bc53720 commit ee1ce84
Show file tree
Hide file tree
Showing 82 changed files with 936 additions and 300 deletions.
35 changes: 29 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ jobs:
run: npm install --silent
- name: Running benchmark
run: node test/benchmark.js --benchmark

profiling:
runs-on: ${{ matrix.os }}
permissions:
pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment
strategy:
matrix:
os: [ubuntu-latest]
node-version: ["14", "16", "18"]
fail-fast: false
env:
comment_file: ".tmp-comment-flamegraph-node${{ matrix.node-version }}.md"
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -54,8 +55,30 @@ jobs:
project: ./.tmp-hexo-theme-unit-test/0x/
login: ${{ secrets.SURGE_LOGIN }}
token: ${{ secrets.SURGE_TOKEN }}
- name: Comment PR
uses: marocchino/sticky-pull-request-comment@v2

- name: save comment to file
if: ${{github.event_name == 'pull_request' }}
run: |
echo "https://${{ github.sha }}-${{ matrix.node-version }}-hexo.surge.sh/flamegraph.html" > ${{env.comment_file}}
- uses: actions/upload-artifact@v4
if: ${{github.event_name == 'pull_request' }}
with:
retention-days: 1
name: comment-node${{ matrix.node-version }}
path: ${{env.comment_file}}

number:
runs-on: ubuntu-latest
if: ${{github.event_name == 'pull_request' }}
env:
pr_number_file: .tmp-comment-pr_number
steps:
- name: save PR number to file
run: |
echo -n "${{ github.event.number }}" > ${{env.pr_number_file}}
- uses: actions/upload-artifact@v4
with:
message: |
Publish flamegraph to https://${{ github.sha }}-${{ matrix.node-version }}-hexo.surge.sh/flamegraph.html
retention-days: 1
name: comment-pr_number
path: ${{env.pr_number_file}}
51 changes: 47 additions & 4 deletions .github/workflows/commenter.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
name: Commenter

on: [pull_request_target]
on:
pull_request_target:

workflow_run:
workflows: ["Benchmark"]
types:
- completed

permissions:
contents: read

jobs:
commenter:
comment-test:
permissions:
pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment
pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment
runs-on: ubuntu-latest
if: ${{github.event_name == 'pull_request_target' }}
steps:
- name: Comment PR
- name: Comment PR - How to test
uses: marocchino/sticky-pull-request-comment@v2
with:
header: How to test
message: |
## How to test
Expand All @@ -23,3 +31,38 @@ jobs:
npm install
npm test
```
comment-flamegraph:
permissions:
pull-requests: write # for marocchino/sticky-pull-request-comment to create or update PR comment
actions: read # get artifact
runs-on: ubuntu-latest
if: ${{github.event_name == 'workflow_run' }}
env:
comment_result: ".tmp-comment-flamegraph.md"
steps:
- name: download artifact
uses: actions/download-artifact@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
run-id: ${{toJSON(github.event.workflow_run.id)}}
pattern: "comment-*"
merge-multiple: true

- name: get PR number
run: |
echo "pr_number=$(cat .tmp-comment-pr_number)" >> "$GITHUB_ENV"
- name: combime comment
run: |
echo "## flamegraph" > ${{env.comment_result}}
echo "" >> ${{env.comment_result}}
cat .tmp-comment-flamegraph-*.md >> ${{env.comment_result}}
- name: Comment PR - flamegraph
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
number: ${{env.pr_number}}
header: flamegraph
path: ${{env.comment_result}}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Also, we welcome PR or issue to [official-plugins](https://github.com/hexojs).

## Sponsors

<a href="https://linktr.ee/rss3"><img src="https://d1fdloi71mui9q.cloudfront.net/8xxahBqRTnecXgXKObeo_L8ks2KjC31fmM5Nd" alt="RSS3" width="200"/></a>
[![Sponsors](https://opencollective.com/hexo/tiers/sponsors.svg?width=600)](https://opencollective.com/hexo)

## License

Expand Down
8 changes: 4 additions & 4 deletions lib/box/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class File {
this.type = type;
}

read(options?: ReadFileOptions): Promise<string | Buffer> {
return readFile(this.source, options);
read(options?: ReadFileOptions): Promise<string> {
return readFile(this.source, options) as Promise<string>;
}

readSync(options?: ReadFileOptions): string | Buffer {
return readFileSync(this.source, options);
readSync(options?: ReadFileOptions): string {
return readFileSync(this.source, options) as string;
}

stat(): Promise<fs.Stats> {
Expand Down
3 changes: 2 additions & 1 deletion lib/box/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { magenta } from 'picocolors';
import { EventEmitter } from 'events';
import { isMatch, makeRe } from 'micromatch';
import type Hexo from '../hexo';
import type { NodeJSLikeCallback } from '../types';

const defaultPattern = new Pattern(() => ({}));

interface Processor {
pattern: Pattern;
process: (file: File) => void;
process: (file?: File) => any;
}

class Box extends EventEmitter {
Expand Down
5 changes: 3 additions & 2 deletions lib/extend/console.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Promise from 'bluebird';
import abbrev from 'abbrev';
import type { NodeJSLikeCallback } from '../types';

type Option = Partial<{
usage: string;
Expand All @@ -19,7 +20,7 @@ interface Args {
_: string[];
[key: string]: string | boolean | string[];
}
type AnyFn = (args: Args) => any;
type AnyFn = (args: Args, callback?: NodeJSLikeCallback<any>) => any;
interface StoreFunction extends AnyFn {
desc?: string;
options?: Option;
Expand All @@ -29,7 +30,7 @@ interface Store {
[key: string]: StoreFunction
}
interface Alias {
[key: string]: string
[abbreviation: string]: string
}

class Console {
Expand Down
3 changes: 2 additions & 1 deletion lib/extend/deployer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Promise from 'bluebird';
import type { NodeJSLikeCallback } from '../types';

interface StoreFunction {
(deployArg: {
type: string;
[key: string]: any
}) : any;
}, callback?: NodeJSLikeCallback<any>) : any;
}
interface Store {
[key: string]: StoreFunction
Expand Down
5 changes: 3 additions & 2 deletions lib/extend/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface FilterOptions {
args?: any[];
}


interface StoreFunction {
(data?: any, ...args: any[]): any;
priority?: number;
Expand Down Expand Up @@ -75,7 +76,7 @@ class Filter {
if (index !== -1) list.splice(index, 1);
}

exec(type: string, data: any[], options: FilterOptions = {}): Promise<any> {
exec(type: string, data: any, options: FilterOptions = {}): Promise<any> {
const filters = this.list(type);
if (filters.length === 0) return Promise.resolve(data);

Expand All @@ -90,7 +91,7 @@ class Filter {
})).then(() => args[0]);
}

execSync(type: string, data: any[], options: FilterOptions = {}) {
execSync(type: string, data: any, options: FilterOptions = {}) {
const filters = this.list(type);
const filtersLen = filters.length;
if (filtersLen === 0) return data;
Expand Down
3 changes: 2 additions & 1 deletion lib/extend/generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Promise from 'bluebird';
import type { NodeJSLikeCallback } from '../types';

interface BaseObj {
path: string;
Expand All @@ -9,7 +10,7 @@ type ReturnType = BaseObj | BaseObj[];
type GeneratorReturnType = ReturnType | Promise<ReturnType>;

interface GeneratorFunction {
(locals: object): GeneratorReturnType;
(locals: object, callback?: NodeJSLikeCallback<any>): GeneratorReturnType;
}

type StoreFunctionReturn = Promise<ReturnType>;
Expand Down
4 changes: 3 additions & 1 deletion lib/extend/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Promise from 'bluebird';
import type { NodeJSLikeCallback } from '../types';

interface StoreFunction {
(args: any): any
(args: any, callback?: NodeJSLikeCallback<any>): any
}

interface Store {
Expand Down
9 changes: 5 additions & 4 deletions lib/extend/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { extname } from 'path';
import Promise from 'bluebird';
import type { NodeJSLikeCallback } from '../types';

const getExtname = (str: string) => {
if (typeof str !== 'string') return '';
Expand All @@ -13,15 +14,15 @@ export interface StoreFunctionData {
text?: string;
engine?: string;
toString?: any;
onRenderEnd?: any;
onRenderEnd?: (...args: any[]) => any;
}

export interface StoreSyncFunction {
[x: string]: any;
(
data: StoreFunctionData,
options: object,
// callback: NodeJSLikeCallback<string>
// callback?: NodeJSLikeCallback<string>
): any;
output?: string;
compile?: (local: object) => any;
Expand All @@ -30,6 +31,7 @@ export interface StoreFunction {
(
data: StoreFunctionData,
options: object,
callback?: NodeJSLikeCallback<any>
): Promise<any>;
(
data: StoreFunctionData,
Expand Down Expand Up @@ -57,7 +59,7 @@ class Renderer {
this.storeSync = {};
}

list(sync: boolean): Store | SyncStore {
list(sync = false): Store | SyncStore {
return sync ? this.storeSync : this.store;
}

Expand Down Expand Up @@ -97,7 +99,6 @@ class Renderer {
this.storeSync[name].output = output;

this.store[name] = Promise.method(fn);
// eslint-disable-next-line no-extra-parens
this.store[name].disableNunjucks = (fn as StoreFunction).disableNunjucks;
} else {
if (fn.length > 2) fn = Promise.promisify(fn);
Expand Down
11 changes: 8 additions & 3 deletions lib/extend/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { stripIndent } from 'hexo-util';
import { cyan, magenta, red, bold } from 'picocolors';
import { Environment } from 'nunjucks';
import Promise from 'bluebird';
import type { NodeJSLikeCallback } from '../types';

const rSwigRawFullBlock = /{% *raw *%}/;
const rCodeTag = /<code[^<>]*>[\s\S]+?<\/code>/g;
const escapeSwigTag = (str: string) => str.replace(/{/g, '&#123;').replace(/}/g, '&#125;');

interface TagFunction {
(args: any[], content: string): string;
(args: any[], content: string, callback?: NodeJSLikeCallback<any>): string | PromiseLike<string>;
}
interface AsyncTagFunction {
(args: any[], content: string): Promise<string>;
Expand Down Expand Up @@ -251,14 +253,17 @@ class Tag {
if (env.hasExtension(name)) env.removeExtension(name);
}

render(str: string, options: { source?: string } = {}, callback?: NodeJSLikeCallback<any>): Promise<any> {
render(str: string): Promise<any>;
render(str: string, callback: NodeJSLikeCallback<any>): Promise<any>;
render(str: string, options: { source?: string, [key: string]: any }, callback?: NodeJSLikeCallback<any>): Promise<any>;
render(str: string, options: { source?: string, [key: string]: any } | NodeJSLikeCallback<any> = {}, callback?: NodeJSLikeCallback<any>): Promise<any> {
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}

// Get path of post from source
const { source = '' } = options;
const { source = '' } = options as { source?: string };

return Promise.fromCallback(cb => {
this.env.renderString(
Expand Down
4 changes: 3 additions & 1 deletion lib/hexo/default_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export = {
wrap: true,
exclude_languages: [],
language_attr: false,
hljs: false
hljs: false,
line_threshold: 0,
first_line_number: 'always1'
},
prismjs: {
preprocess: true,
Expand Down
Loading

0 comments on commit ee1ce84

Please sign in to comment.