diff --git a/lib/box/file.ts b/lib/box/file.ts index 30d71cdddf..6515a74582 100644 --- a/lib/box/file.ts +++ b/lib/box/file.ts @@ -3,16 +3,38 @@ import { readFile, readFileSync, stat, statSync, type ReadFileOptions } from 'he import type fs from 'fs'; class File { + + /** + * Full path of the file + */ public source: string; + + /** + * Relative path to the box of the file + */ public path: string; + + /** + * The information from path matching. + */ public params: any; - public type: string; + + /** + * File type. The value can be create, update, skip, delete. + */ + // eslint-disable-next-line no-use-before-define + public type: typeof File.TYPE_CREATE | typeof File.TYPE_UPDATE | typeof File.TYPE_SKIP | typeof File.TYPE_DELETE; static TYPE_CREATE: 'create'; static TYPE_UPDATE: 'update'; static TYPE_SKIP: 'skip'; static TYPE_DELETE: 'delete'; - constructor({ source, path, params, type }) { + constructor({ source, path, params, type }: { + source: string; + path: string; + params: any; + type: typeof File.TYPE_CREATE | typeof File.TYPE_UPDATE | typeof File.TYPE_SKIP | typeof File.TYPE_DELETE; + }) { this.source = source; this.path = path; this.params = params; diff --git a/lib/box/index.ts b/lib/box/index.ts index 4da7c69d4e..9ac0703f7a 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -8,6 +8,7 @@ import { EventEmitter } from 'events'; import { isMatch, makeRe } from 'micromatch'; import type Hexo from '../hexo'; import type { NodeJSLikeCallback } from '../types'; +import type fs from 'fs'; const defaultPattern = new Pattern(() => ({})); @@ -101,7 +102,7 @@ class Box extends EventEmitter { _readDir(base: string, prefix = ''): BlueBirdPromise { const { context: ctx } = this; - const results = []; + const results: string[] = []; return readDirWalker(ctx, base, results, this.ignore, prefix) .return(results) .map(path => this._checkFileStatus(path)) @@ -266,30 +267,30 @@ function toRegExp(ctx: Hexo, arg: string): RegExp | null { return result; } -function isIgnoreMatch(path: string, ignore: string | any[]): boolean { +function isIgnoreMatch(path: string, ignore: string | string[]): boolean { return path && ignore && ignore.length && isMatch(path, ignore); } -function readDirWalker(ctx: Hexo, base: string, results: any[], ignore: any, prefix: string): BlueBirdPromise { +function readDirWalker(ctx: Hexo, base: string, results: string[], ignore: string | string[], prefix: string): BlueBirdPromise { if (isIgnoreMatch(base, ignore)) return BlueBirdPromise.resolve(); return BlueBirdPromise.map(readdir(base).catch(err => { ctx.log.error({ err }, 'Failed to read directory: %s', base); if (err && err.code === 'ENOENT') return []; throw err; - }), async path => { - const fullpath = join(base, path); - const stats = await stat(fullpath).catch(err => { - ctx.log.error({ err }, 'Failed to stat file: %s', fullpath); + }), async (path: string) => { + const fullPath = join(base, path); + const stats: fs.Stats = await stat(fullPath).catch(err => { + ctx.log.error({ err }, 'Failed to stat file: %s', fullPath); if (err && err.code === 'ENOENT') return null; throw err; }); const prefixPath = `${prefix}${path}`; if (stats) { if (stats.isDirectory()) { - return readDirWalker(ctx, fullpath, results, ignore, `${prefixPath}/`); + return readDirWalker(ctx, fullPath, results, ignore, `${prefixPath}/`); } - if (!isIgnoreMatch(fullpath, ignore)) { + if (!isIgnoreMatch(fullPath, ignore)) { results.push(prefixPath); } } diff --git a/lib/extend/console.ts b/lib/extend/console.ts index 0c32af063c..6e27f6c70b 100644 --- a/lib/extend/console.ts +++ b/lib/extend/console.ts @@ -33,6 +33,9 @@ interface Alias { [abbreviation: string]: string } +/** + * The console forms the bridge between Hexo and its users. It registers and describes the available console commands. + */ class Console { public store: Store; public alias: Alias; diff --git a/lib/extend/deployer.ts b/lib/extend/deployer.ts index 5014433c4e..c6def5cfc5 100644 --- a/lib/extend/deployer.ts +++ b/lib/extend/deployer.ts @@ -11,6 +11,9 @@ interface Store { [key: string]: StoreFunction } +/** + * A deployer helps users quickly deploy their site to a remote server without complicated commands. + */ class Deployer { public store: Store; diff --git a/lib/extend/filter.ts b/lib/extend/filter.ts index 98b34de1f3..a05ef42a49 100644 --- a/lib/extend/filter.ts +++ b/lib/extend/filter.ts @@ -21,6 +21,10 @@ interface Store { [key: string]: StoreFunction[] } +/** + * A filter is used to modify some specified data. Hexo passes data to filters in sequence and the filters then modify the data one after the other. + * This concept was borrowed from WordPress. + */ class Filter { public store: Store; diff --git a/lib/extend/generator.ts b/lib/extend/generator.ts index 6370f5029e..de4add89a2 100644 --- a/lib/extend/generator.ts +++ b/lib/extend/generator.ts @@ -23,6 +23,9 @@ interface Store { [key: string]: StoreFunction } +/** + * A generator builds routes based on processed files. + */ class Generator { public id: number; public store: Store; diff --git a/lib/extend/helper.ts b/lib/extend/helper.ts index f167282371..65932a6184 100644 --- a/lib/extend/helper.ts +++ b/lib/extend/helper.ts @@ -6,7 +6,9 @@ interface Store { [key: string]: StoreFunction } - +/** + * A helper makes it easy to quickly add snippets to your templates. We recommend using helpers instead of templates when you’re dealing with more complicated code. + */ class Helper { public store: Store; diff --git a/lib/extend/injector.ts b/lib/extend/injector.ts index edb4a45094..3c0dc5f229 100644 --- a/lib/extend/injector.ts +++ b/lib/extend/injector.ts @@ -8,6 +8,10 @@ type Store = { }; }; +/** + * An injector is used to add static code snippet to the `` or/and `` of generated HTML files. + * Hexo run injector before `after_render:html` filter is executed. + */ class Injector { public store: Store; public cache: any; diff --git a/lib/extend/migrator.ts b/lib/extend/migrator.ts index ce5ae77544..30fb412da7 100644 --- a/lib/extend/migrator.ts +++ b/lib/extend/migrator.ts @@ -9,6 +9,9 @@ interface Store { [key: string]: StoreFunction } +/** + * A migrator helps users migrate from other systems to Hexo. + */ class Migrator { public store: Store; diff --git a/lib/extend/processor.ts b/lib/extend/processor.ts index ce73da1031..f2f2be60e8 100644 --- a/lib/extend/processor.ts +++ b/lib/extend/processor.ts @@ -12,6 +12,10 @@ type Store = { }[]; type patternType = Exclude[0], ((str: string) => string)>; + +/** + * A processor is used to process source files in the `source` folder. + */ class Processor { public store: Store; diff --git a/lib/extend/renderer.ts b/lib/extend/renderer.ts index 530b071e18..18413f3e14 100644 --- a/lib/extend/renderer.ts +++ b/lib/extend/renderer.ts @@ -50,6 +50,9 @@ interface Store { [key: string]: StoreFunction; } +/** + * A renderer is used to render content. + */ class Renderer { public store: Store; public storeSync: SyncStore; diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index b9648d3297..278a96deb5 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -200,6 +200,9 @@ type RegisterOptions = { ends?: boolean; } +/** + * A tag allows users to quickly and easily insert snippets into their posts. + */ class Tag { public env: Environment; public source: string; diff --git a/lib/hexo/default_config.ts b/lib/hexo/default_config.ts index 390b8f32f5..87b40d6e06 100644 --- a/lib/hexo/default_config.ts +++ b/lib/hexo/default_config.ts @@ -23,7 +23,7 @@ export = { category_dir: 'categories', code_dir: 'downloads/code', i18n_dir: ':lang', - skip_render: [], + skip_render: [] as string[], // Writing new_post_name: ':title.md', default_layout: 'post', @@ -44,7 +44,7 @@ export = { line_number: true, tab_replace: '', wrap: true, - exclude_languages: [], + exclude_languages: [] as string[], language_attr: false, hljs: false, line_threshold: 0, @@ -55,7 +55,7 @@ export = { preprocess: true, line_number: true, tab_replace: '', - exclude_languages: [], + exclude_languages: [] as string[], strip_indent: true }, use_filename_as_post_title: false, diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index b9ca764dd4..93337a5fac 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -111,13 +111,37 @@ function debounce(func: () => void, wait: number): () => void { } interface Args { + + /** + * Enable debug mode. Display debug messages in the terminal and save debug.log in the root directory. + */ debug?: boolean; + + /** + * Enable safe mode. Don’t load any plugins. + */ safe?: boolean; + + /** + * Enable silent mode. Don’t display any messages in the terminal. + */ silent?: boolean; + + /** + * Enable to add drafts to the posts list. + */ draft?: boolean; + + /** + * Enable to add drafts to the posts list. + */ drafts?: boolean; _?: string[]; output?: string; + + /** + * Specify the path of the configuration file. + */ config?: string; [key: string]: any; } @@ -407,6 +431,11 @@ class Hexo extends EventEmitter { }); } + /** + * Load configuration and plugins. + * @returns {Promise} + * @link https://hexo.io/api#Initialize + */ init(): Promise { this.log.debug('Hexo version: %s', magenta(this.version)); this.log.debug('Working directory: %s', magenta(tildify(this.base_dir))); @@ -434,6 +463,14 @@ class Hexo extends EventEmitter { }); } + /** + * Call any console command explicitly. + * @param name + * @param args + * @param callback + * @returns {Promise} + * @link https://hexo.io/api#Execute-Commands + */ call(name: string, callback?: NodeJSLikeCallback): Promise; call(name: string, args: object, callback?: NodeJSLikeCallback): Promise; call(name: string, args?: object | NodeJSLikeCallback, callback?: NodeJSLikeCallback): Promise { @@ -500,6 +537,12 @@ class Hexo extends EventEmitter { return args.draft || args.drafts || this.config.render_drafts; } + /** + * Load all files in the source folder as well as the theme data. + * @param callback + * @returns {Promise} + * @link https://hexo.io/api#Load-Files + */ load(callback?: NodeJSLikeCallback): Promise { return loadDatabase(this).then(() => { this.log.info('Start processing'); @@ -514,6 +557,13 @@ class Hexo extends EventEmitter { }).asCallback(callback); } + /** + * Load all files in the source folder as well as the theme data. + * Start watching for file changes continuously. + * @param callback + * @returns {Promise} + * @link https://hexo.io/api#Load-Files + */ watch(callback?: NodeJSLikeCallback): Promise { let useCache = false; const { cache } = Object.assign({ @@ -622,7 +672,7 @@ class Hexo extends EventEmitter { // add Route const path = route.format(generatorResult.path); // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore + // @ts-expect-error const { data, layout } = generatorResult; if (!layout) { @@ -666,6 +716,12 @@ class Hexo extends EventEmitter { }); } + /** + * Exit gracefully and finish up important things such as saving the database. + * @param err + * @returns {Promise} + * @link https://hexo.io/api/#Exit + */ exit(err?: any): Promise { if (err) { this.log.fatal( diff --git a/lib/models/asset.ts b/lib/models/asset.ts index 5a761192da..3520bad85a 100644 --- a/lib/models/asset.ts +++ b/lib/models/asset.ts @@ -1,6 +1,7 @@ import warehouse from 'warehouse'; import { join } from 'path'; import type Hexo from '../hexo'; +import type { AssetSchema } from '../types'; export = (ctx: Hexo) => { const Asset = new warehouse.Schema({ @@ -10,7 +11,7 @@ export = (ctx: Hexo) => { renderable: {type: Boolean, default: true} }); - Asset.virtual('source').get(function() { + Asset.virtual('source').get(function(this: AssetSchema) { return join(ctx.base_dir, this._id); }); diff --git a/lib/models/cache.ts b/lib/models/cache.ts index 60db5ce1c4..4189829ec2 100644 --- a/lib/models/cache.ts +++ b/lib/models/cache.ts @@ -1,6 +1,10 @@ import warehouse from 'warehouse'; import Promise from 'bluebird'; import type Hexo from '../hexo'; +import type fs from 'fs'; +import type Model from 'warehouse/dist/model'; +import type Document from 'warehouse/dist/document'; +import type { CacheSchema } from '../types'; export = (ctx: Hexo) => { const Cache = new warehouse.Schema({ @@ -9,13 +13,15 @@ export = (ctx: Hexo) => { modified: {type: Number, default: Date.now() } // UnixTime }); - Cache.static('compareFile', function(id, hashFn, statFn) { - const cache = this.findById(id); + Cache.static('compareFile', function(this: Model, id: string, + hashFn: (id: string) => Promise, + statFn: (id: string) => Promise): Promise<{ type: string }> { + const cache = this.findById(id) as Document; // If cache does not exist, then it must be a new file. We have to get both // file hash and stats. if (!cache) { - return Promise.all([hashFn(id), statFn(id)]).spread((hash, stats) => this.insert({ + return Promise.all([hashFn(id), statFn(id)]).spread((hash: string, stats: fs.Stats) => this.insert({ _id: id, hash, modified: stats.mtime.getTime() @@ -24,10 +30,10 @@ export = (ctx: Hexo) => { }); } - let mtime; + let mtime: number; // Get file stats - return statFn(id).then(stats => { + return statFn(id).then(stats => { mtime = stats.mtime.getTime(); // Skip the file if the modified time is unchanged @@ -39,7 +45,7 @@ export = (ctx: Hexo) => { // Get file hash return hashFn(id); - }).then(result => { + }).then((result: string | object) => { // If the result is an object, skip the following steps because it's an // unchanged file if (typeof result === 'object') return result; @@ -57,6 +63,9 @@ export = (ctx: Hexo) => { cache.hash = hash; cache.modified = mtime; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error + // waiting warehouse v5.0.2 return cache.save().thenReturn({ type: 'update' }); diff --git a/lib/models/category.ts b/lib/models/category.ts index 2fdbfb58df..1a8049d485 100644 --- a/lib/models/category.ts +++ b/lib/models/category.ts @@ -1,6 +1,7 @@ import warehouse from 'warehouse'; import { slugize, full_url_for } from 'hexo-util'; import type Hexo from '../hexo'; +import type { CategorySchema } from '../types'; export = (ctx: Hexo) => { const Category = new warehouse.Schema({ @@ -8,7 +9,7 @@ export = (ctx: Hexo) => { parent: { type: warehouse.Schema.Types.CUID, ref: 'Category'} }); - Category.virtual('slug').get(function() { + Category.virtual('slug').get(function(this: CategorySchema) { let name = this.name; if (!name) return; @@ -28,7 +29,7 @@ export = (ctx: Hexo) => { return str; }); - Category.virtual('path').get(function() { + Category.virtual('path').get(function(this: CategorySchema) { let catDir = ctx.config.category_dir; if (catDir === '/') catDir = ''; if (!catDir.endsWith('/')) catDir += '/'; @@ -36,11 +37,11 @@ export = (ctx: Hexo) => { return `${catDir + this.slug}/`; }); - Category.virtual('permalink').get(function() { + Category.virtual('permalink').get(function(this: CategorySchema) { return full_url_for.call(ctx, this.path); }); - Category.virtual('posts').get(function() { + Category.virtual('posts').get(function(this: CategorySchema) { const PostCategory = ctx.model('PostCategory'); const ids = PostCategory.find({category_id: this._id}).map(item => item.post_id); @@ -50,14 +51,14 @@ export = (ctx: Hexo) => { }); }); - Category.virtual('length').get(function() { + Category.virtual('length').get(function(this: CategorySchema) { const PostCategory = ctx.model('PostCategory'); return PostCategory.find({category_id: this._id}).length; }); // Check whether a category exists - Category.pre('save', data => { + Category.pre('save', (data: CategorySchema) => { const { name, parent } = data; if (!name) return; @@ -73,7 +74,7 @@ export = (ctx: Hexo) => { }); // Remove PostCategory references - Category.pre('remove', data => { + Category.pre('remove', (data: CategorySchema) => { const PostCategory = ctx.model('PostCategory'); return PostCategory.remove({category_id: data._id}); }); diff --git a/lib/models/page.ts b/lib/models/page.ts index f1a96922d7..b3ee6f6d07 100644 --- a/lib/models/page.ts +++ b/lib/models/page.ts @@ -4,6 +4,7 @@ import Moment from './types/moment'; import moment from 'moment'; import { full_url_for } from 'hexo-util'; import type Hexo from '../hexo'; +import type { PageSchema } from '../types'; export = (ctx: Hexo) => { const Page = new warehouse.Schema({ @@ -30,11 +31,11 @@ export = (ctx: Hexo) => { more: {type: String} }); - Page.virtual('permalink').get(function() { + Page.virtual('permalink').get(function(this: PageSchema) { return full_url_for.call(ctx, this.path); }); - Page.virtual('full_source').get(function() { + Page.virtual('full_source').get(function(this: PageSchema) { return join(ctx.source_dir, this.source || ''); }); diff --git a/lib/models/post.ts b/lib/models/post.ts index 208e8ea477..31c2aeccf8 100644 --- a/lib/models/post.ts +++ b/lib/models/post.ts @@ -5,12 +5,13 @@ import Promise from 'bluebird'; import Moment from './types/moment'; import { full_url_for, Cache } from 'hexo-util'; import type Hexo from '../hexo'; +import type { CategorySchema, PostCategorySchema, PostSchema } from '../types'; -function pickID(data) { +function pickID(data: PostSchema | PostCategorySchema) { return data._id; } -function removeEmptyTag(tags) { +function removeEmptyTag(tags: string[]) { return tags.filter(tag => tag != null && tag !== '').map(tag => `${tag}`); } @@ -44,25 +45,25 @@ export = (ctx: Hexo) => { more: {type: String} }); - Post.virtual('path').get(function() { + Post.virtual('path').get(function(this: PostSchema) { const path = ctx.execFilterSync('post_permalink', this, {context: ctx}); return typeof path === 'string' ? path : ''; }); - Post.virtual('permalink').get(function() { + Post.virtual('permalink').get(function(this: PostSchema) { return full_url_for.call(ctx, this.path); }); - Post.virtual('full_source').get(function() { + Post.virtual('full_source').get(function(this: PostSchema) { return join(ctx.source_dir, this.source || ''); }); - Post.virtual('asset_dir').get(function() { + Post.virtual('asset_dir').get(function(this: PostSchema) { const src = this.full_source; return src.substring(0, src.length - extname(src).length) + sep; }); - Post.virtual('tags').get(function() { + Post.virtual('tags').get(function(this: PostSchema) { return tagsGetterCache.apply(this._id, () => { const PostTag = ctx.model('PostTag'); const Tag = ctx.model('Tag'); @@ -73,12 +74,12 @@ export = (ctx: Hexo) => { }); }); - Post.method('notPublished', function() { + Post.method('notPublished', function(this: PostSchema) { // The same condition as ctx._bindLocals - return (!ctx.config.future && this.date > Date.now()) || (!ctx._showDrafts() && this.published === false); + return (!ctx.config.future && this.date.valueOf() > Date.now()) || (!ctx._showDrafts() && this.published === false); }); - Post.method('setTags', function(tags) { + Post.method('setTags', function(this: PostSchema, tags: string[]) { if (this.notPublished()) { // Ignore tags of draft posts // If the post is unpublished then the tag needs to be removed, thus the function cannot be returned early here @@ -122,7 +123,7 @@ export = (ctx: Hexo) => { }).map(tag => PostTag.removeById(tag)); }); - Post.virtual('categories').get(function() { + Post.virtual('categories').get(function(this: PostSchema) { const PostCategory = ctx.model('PostCategory'); const Category = ctx.model('Category'); @@ -131,7 +132,7 @@ export = (ctx: Hexo) => { return Category.find({_id: {$in: ids}}); }); - Post.method('setCategories', function(cats: string[]) { + Post.method('setCategories', function(this: PostSchema, cats: (string | string[])[]) { if (this.notPublished()) { cats = []; } @@ -145,7 +146,7 @@ export = (ctx: Hexo) => { const PostCategory = ctx.model('PostCategory'); const Category = ctx.model('Category'); const id = this._id; - const allIds = []; + const allIds: string[] = []; const existed = PostCategory.find({post_id: id}, {lean: true}).map(pickID); const hasHierarchy = cats.filter(Array.isArray).length > 0; @@ -157,7 +158,7 @@ export = (ctx: Hexo) => { // MUST USE "Promise.each". return Promise.each(catHierarchy, (cat, i) => { // Find the category by name - const data = Category.findOne({ + const data: CategorySchema = Category.findOne({ name: cat, parent: i ? parentIds[i - 1] : {$exists: false} }, {lean: true}); @@ -174,14 +175,14 @@ export = (ctx: Hexo) => { return Category.insert(obj).catch(err => { // Try to find the category again. Throw the error if not found - const data = Category.findOne({ + const data: CategorySchema = Category.findOne({ name: cat, parent: i ? parentIds[i - 1] : {$exists: false} }, {lean: true}); if (data) return data; throw err; - }).then(data => { + }).then((data: CategorySchema) => { allIds.push(data._id); parentIds.push(data._id); return data; @@ -189,10 +190,10 @@ export = (ctx: Hexo) => { }); }; - return (hasHierarchy ? Promise.each(cats, addHierarchy) : Promise.resolve(addHierarchy(cats)) + return (hasHierarchy ? Promise.each(cats, addHierarchy) : Promise.resolve(addHierarchy(cats as string[])) ).then(() => allIds).map(catId => { // Find the reference - const ref = PostCategory.findOne({post_id: id, category_id: catId}, {lean: true}); + const ref: PostCategorySchema = PostCategory.findOne({post_id: id, category_id: catId}, {lean: true}); if (ref) return ref; // Insert the reference if not exist @@ -200,24 +201,24 @@ export = (ctx: Hexo) => { post_id: id, category_id: catId }); - }).then(postCats => // Remove old categories + }).then((postCats: PostCategorySchema[]) => // Remove old categories existed.filter(item => !postCats.map(pickID).includes(item))).map(cat => PostCategory.removeById(cat)); }); // Remove PostTag references - Post.pre('remove', data => { + Post.pre('remove', (data: PostSchema) => { const PostTag = ctx.model('PostTag'); return PostTag.remove({post_id: data._id}); }); // Remove PostCategory references - Post.pre('remove', data => { + Post.pre('remove', (data: PostSchema) => { const PostCategory = ctx.model('PostCategory'); return PostCategory.remove({post_id: data._id}); }); // Remove assets - Post.pre('remove', data => { + Post.pre('remove', (data: PostSchema) => { const PostAsset = ctx.model('PostAsset'); return PostAsset.remove({post: data._id}); }); diff --git a/lib/models/post_asset.ts b/lib/models/post_asset.ts index 8572029b8c..07c8ceebbe 100644 --- a/lib/models/post_asset.ts +++ b/lib/models/post_asset.ts @@ -1,6 +1,7 @@ import warehouse from 'warehouse'; import { join, posix } from 'path'; import type Hexo from '../hexo'; +import type { PostAssetSchema } from '../types'; export = (ctx: Hexo) => { const PostAsset = new warehouse.Schema({ @@ -11,7 +12,7 @@ export = (ctx: Hexo) => { renderable: {type: Boolean, default: true} }); - PostAsset.virtual('path').get(function() { + PostAsset.virtual('path').get(function(this: PostAssetSchema) { const Post = ctx.model('Post'); const post = Post.findById(this.post); if (!post) return; @@ -23,7 +24,7 @@ export = (ctx: Hexo) => { return posix.join(post.path.replace(/\.html?$/, ''), this.slug); }); - PostAsset.virtual('source').get(function() { + PostAsset.virtual('source').get(function(this: PostAssetSchema) { return join(ctx.base_dir, this._id); }); diff --git a/lib/models/tag.ts b/lib/models/tag.ts index 84a118aa25..b203f027c1 100644 --- a/lib/models/tag.ts +++ b/lib/models/tag.ts @@ -2,13 +2,14 @@ import warehouse from 'warehouse'; import { slugize, full_url_for } from 'hexo-util'; const { hasOwnProperty: hasOwn } = Object.prototype; import type Hexo from '../hexo'; +import type { TagSchema } from '../types'; export = (ctx: Hexo) => { const Tag = new warehouse.Schema({ name: {type: String, required: true} }); - Tag.virtual('slug').get(function() { + Tag.virtual('slug').get(function(this: TagSchema) { const map = ctx.config.tag_map || {}; let name = this.name; if (!name) return; @@ -20,18 +21,18 @@ export = (ctx: Hexo) => { return slugize(name, {transform: ctx.config.filename_case}); }); - Tag.virtual('path').get(function() { + Tag.virtual('path').get(function(this: TagSchema) { let tagDir = ctx.config.tag_dir; if (!tagDir.endsWith('/')) tagDir += '/'; return `${tagDir + this.slug}/`; }); - Tag.virtual('permalink').get(function() { + Tag.virtual('permalink').get(function(this: TagSchema) { return full_url_for.call(ctx, this.path); }); - Tag.virtual('posts').get(function() { + Tag.virtual('posts').get(function(this: TagSchema) { const PostTag = ctx.model('PostTag'); const ids = PostTag.find({tag_id: this._id}).map(item => item.post_id); @@ -41,7 +42,7 @@ export = (ctx: Hexo) => { }); }); - Tag.virtual('length').get(function() { + Tag.virtual('length').get(function(this: TagSchema) { // Note: this.posts.length is also working // But it's slow because `find` has to iterate over all posts const PostTag = ctx.model('PostTag'); @@ -50,7 +51,7 @@ export = (ctx: Hexo) => { }); // Check whether a tag exists - Tag.pre('save', data => { + Tag.pre('save', (data: TagSchema) => { const { name } = data; if (!name) return; @@ -63,7 +64,7 @@ export = (ctx: Hexo) => { }); // Remove PostTag references - Tag.pre('remove', data => { + Tag.pre('remove', (data: TagSchema) => { const PostTag = ctx.model('PostTag'); return PostTag.remove({tag_id: data._id}); }); diff --git a/lib/plugins/console/list/category.ts b/lib/plugins/console/list/category.ts index a1c6527c80..e9424a3588 100644 --- a/lib/plugins/console/list/category.ts +++ b/lib/plugins/console/list/category.ts @@ -2,11 +2,13 @@ import { underline } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; import type Hexo from '../../../hexo'; +import type { CategorySchema } from '../../../types'; +import type Model from 'warehouse/dist/model'; function listCategory(this: Hexo): void { - const categories = this.model('Category'); + const categories: Model = this.model('Category'); - const data = categories.sort({name: 1}).map(cate => [cate.name, String(cate.length)]); + const data = categories.sort({name: 1}).map((cate: CategorySchema) => [cate.name, String(cate.length)]); // Table header const header = ['Name', 'Posts'].map(str => underline(str)); diff --git a/lib/plugins/console/list/page.ts b/lib/plugins/console/list/page.ts index 8b9de1bc09..e3a371e8d4 100644 --- a/lib/plugins/console/list/page.ts +++ b/lib/plugins/console/list/page.ts @@ -2,11 +2,13 @@ import { magenta, underline, gray } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; import type Hexo from '../../../hexo'; +import type { PageSchema } from '../../../types'; +import type Model from 'warehouse/dist/model'; function listPage(this: Hexo): void { - const Page = this.model('Page'); + const Page: Model = this.model('Page'); - const data = Page.sort({date: 1}).map(page => { + const data = Page.sort({date: 1}).map((page: PageSchema) => { const date = page.date.format('YYYY-MM-DD'); return [gray(date), page.title, magenta(page.source)]; }); diff --git a/lib/plugins/console/list/post.ts b/lib/plugins/console/list/post.ts index 280b339df8..e213b7577d 100644 --- a/lib/plugins/console/list/post.ts +++ b/lib/plugins/console/list/post.ts @@ -2,15 +2,17 @@ import { gray, magenta, underline } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; import type Hexo from '../../../hexo'; +import type { PostSchema } from '../../../types'; +import type Model from 'warehouse/dist/model'; function mapName(item) { return item.name; } function listPost(this: Hexo): void { - const Post = this.model('Post'); + const Post: Model = this.model('Post'); - const data = Post.sort({published: -1, date: 1}).map(post => { + const data = Post.sort({published: -1, date: 1}).map((post: PostSchema) => { const date = post.published ? post.date.format('YYYY-MM-DD') : 'Draft'; const tags = post.tags.map(mapName); const categories = post.categories.map(mapName); diff --git a/lib/plugins/console/list/route.ts b/lib/plugins/console/list/route.ts index 2c15e217cc..3e2c1f8a85 100644 --- a/lib/plugins/console/list/route.ts +++ b/lib/plugins/console/list/route.ts @@ -14,9 +14,9 @@ function listRoute(this: Hexo): void { console.log(s); } -function buildTree(routes) { - const obj = {}; - let cursor; +function buildTree(routes: string[]) { + const obj: Record = {}; + let cursor: typeof obj; for (let i = 0, len = routes.length; i < len; i++) { const item = routes[i].split('/'); @@ -32,7 +32,7 @@ function buildTree(routes) { return obj; } -function buildNodes(tree) { +function buildNodes(tree: Record) { const nodes = []; for (const [key, item] of Object.entries(tree)) { diff --git a/lib/plugins/console/list/tag.ts b/lib/plugins/console/list/tag.ts index 4ce37595d1..b34d7ad6c3 100644 --- a/lib/plugins/console/list/tag.ts +++ b/lib/plugins/console/list/tag.ts @@ -2,11 +2,13 @@ import { magenta, underline } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; import type Hexo from '../../../hexo'; +import type { TagSchema } from '../../../types'; +import type Model from 'warehouse/dist/model'; function listTag(this: Hexo): void { - const Tag = this.model('Tag'); + const Tag: Model = this.model('Tag'); - const data = Tag.sort({name: 1}).map(tag => [tag.name, String(tag.length), magenta(tag.path)]); + const data = Tag.sort({name: 1}).map((tag: TagSchema) => [tag.name, String(tag.length), magenta(tag.path)]); // Table header const header = ['Name', 'Posts', 'Path'].map(str => underline(str)); diff --git a/lib/plugins/filter/new_post_path.ts b/lib/plugins/filter/new_post_path.ts index b25a1f9d2c..39de6dc5b2 100644 --- a/lib/plugins/filter/new_post_path.ts +++ b/lib/plugins/filter/new_post_path.ts @@ -18,7 +18,7 @@ const reservedKeys = { hash: true }; -function newPostPathFilter(this: Hexo, data: PostSchema = {}, replace?: boolean): Promise { +function newPostPathFilter(this: Hexo, data: Partial = {}, replace?: boolean): Promise { const sourceDir = this.source_dir; const draftDir = join(sourceDir, '_drafts'); const postDir = join(sourceDir, '_posts'); diff --git a/lib/plugins/processor/post.ts b/lib/plugins/processor/post.ts index 856fff5ba2..0e185c5a77 100644 --- a/lib/plugins/processor/post.ts +++ b/lib/plugins/processor/post.ts @@ -9,6 +9,7 @@ import type { _File } from '../../box'; import type Hexo from '../../hexo'; import type { Stats } from 'fs'; import { PostSchema } from '../../types'; +import type Document from 'warehouse/dist/document'; const postDir = '_posts/'; const draftDir = '_drafts/'; @@ -284,7 +285,7 @@ function processAsset(ctx: Hexo, file: _File) { return; } - const savePostAsset = (post: PostSchema) => { + const savePostAsset = (post: Document) => { return PostAsset.save({ _id: id, slug: file.source.substring(post.asset_dir.length), diff --git a/lib/types.ts b/lib/types.ts index 4ca98f4e16..e454ab95b1 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -30,7 +30,8 @@ import type search_form from './plugins/helper/search_form'; import type tag_cloud from './plugins/helper/tagcloud'; import type toc from './plugins/helper/toc'; import type url_for from './plugins/helper/url_for'; -import Model from 'warehouse/dist/model'; +import type Model from 'warehouse/dist/model'; +import type Document from 'warehouse/dist/document'; export type NodeJSLikeCallback = (err: E, result?: R) => void @@ -47,30 +48,75 @@ export interface RenderData { } // Schema +export interface TagSchema { + id?: string; + _id?: string; + name: string; + slug: string; + path: string; + permalink: string; + posts: any; + length: number; +} + +export interface CategorySchema { + id?: string; + _id?: string; + name: string; + parent?: string; + slug: string; + path: string; + permalink: string; + posts: any; + length: number; +} + +export interface PostCategorySchema { + _id?: string; + post_id: string; + category_id: string; +} + +export interface PostTagSchema { + _id?: string; + post_id: string; + tag_id: string; +} + +export interface PostAssetSchema { + _id: string; + slug: string; + modified: boolean; + post: string; + renderable: boolean; + path: string; + source: string; +} + export interface PostSchema { - id?: string | number; - _id?: string | number; - title?: string; - date?: moment.Moment, - updated?: moment.Moment, - comments?: boolean; - layout?: string; - _content?: string; - source?: string; - slug?: string; + id?: string; + _id?: string; + title: string; + date: moment.Moment, + updated: moment.Moment, + comments: boolean; + layout: string; + _content: string; + source: string; + slug: string; photos?: string[]; - raw?: string; - published?: boolean; + raw: string; + published: boolean; content?: string; excerpt?: string; more?: string; author?: string; - asset_dir?: string; - full_source?: string; - path?: string; - permalink?: string; - categories?: any; - tags?: any; + asset_dir: string; + full_source: string; + path: string; + permalink: string; + categories: Query; + tags?: Query; __permalink?: string; __post?: boolean; canonical_path?: string; @@ -83,25 +129,28 @@ export interface PostSchema { total?: number; description?: string; [key: string]: any; + notPublished: () => boolean; + setTags: (tags: string[]) => any; + setCategories: (cats: (string | string[])[]) => any; } export interface PageSchema { - _id?: string | number; - title?: string; - date?: moment.Moment, - updated?: moment.Moment, - comments?: boolean; - layout?: string; - _content?: string; - source?: string; - path?: string; - raw?: string; + _id?: string; + title: string; + date: moment.Moment, + updated: moment.Moment, + comments: boolean; + layout: string; + _content: string; + source: string; + path: string; + raw: string; content?: string; excerpt?: string; more?: string; + full_source: string; + permalink: string; author?: string; - full_source?: string; - permalink?: string; tags?: any; canonical_path?: string; lang?: string; @@ -114,24 +163,6 @@ export interface PageSchema { description?: string; } -export interface CategorySchema { - id?: string | number; - _id?: string | number; - name?: string; - parent?: string | number; - slug?: string; - path?: string; - permalink?: string; - posts?: any; - length?: number; -} - -export interface TagSchema { - id?: string | number; - _id?: string | number; - name?: string; -} - export interface AssetSchema { _id?: string; path: string; @@ -140,6 +171,12 @@ export interface AssetSchema { source: string; } +export interface CacheSchema { + _id: string; + hash: string; + modified: number; +} + export interface LocalsType { page: PostSchema | PageSchema; path: string; @@ -225,7 +262,7 @@ export type SimplePostGenerator = { export type NormalPostGenerator = { path: string; layout: string[]; - data: PostSchema; + data: PostSchema | Document; } export type PostGenerator = SimplePostGenerator | NormalPostGenerator; diff --git a/package.json b/package.json index b9009c2c0a..0fe26c2cba 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,9 @@ "@types/abbrev": "^1.1.3", "@types/bluebird": "^3.5.37", "@types/chai": "^4.3.11", + "@types/graceful-fs": "^4.1.9", "@types/js-yaml": "^4.0.9", + "@types/micromatch": "^4.0.7", "@types/mocha": "^10.0.6", "@types/node": "^18.11.8 <18.19.9", "@types/nunjucks": "^3.2.2", diff --git a/test/scripts/box/box.ts b/test/scripts/box/box.ts index d6d3d35b57..c6a57d19df 100644 --- a/test/scripts/box/box.ts +++ b/test/scripts/box/box.ts @@ -2,8 +2,7 @@ import { join, sep } from 'path'; import { appendFile, mkdir, mkdirs, rename, rmdir, stat, unlink, writeFile } from 'hexo-fs'; import { hash, Pattern } from 'hexo-util'; import { spy, match, assert as sinonAssert } from 'sinon'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import Box from '../../../lib/box'; import chai from 'chai'; @@ -65,7 +64,7 @@ describe('Box', () => { it('addProcessor() - no fn', () => { const box = newBox(); - // @ts-ignore + // @ts-expect-error should.throw(() => box.addProcessor('test'), 'fn must be a function'); }); @@ -77,7 +76,7 @@ describe('Box', () => { data[file.path] = file; }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(join(box.base, 'a.txt'), 'a'), writeFile(join(box.base, 'b', 'c.js'), 'c') ]); @@ -125,7 +124,7 @@ describe('Box', () => { const processor = spy(); box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ writeFile(path, 'a'), box.Cache.insert({ _id: cacheId, @@ -216,7 +215,7 @@ describe('Box', () => { const processor = spy(); box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ mkdirs(box.base), box.Cache.insert({ _id: cacheId @@ -281,7 +280,7 @@ describe('Box', () => { data[file.path] = file; }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(join(box.base, 'foo.txt'), 'foo'), writeFile(join(box.base, 'ignore_me', 'bar.txt'), 'ignore_me') ]); @@ -300,7 +299,7 @@ describe('Box', () => { data[file.path] = file; }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(join(box.base, 'foo.txt'), 'foo'), writeFile(join(box.base, 'ignore_me', 'bar.txt'), 'ignore_me'), writeFile(join(box.base, 'ignore_me_too.txt'), 'ignore_me_too') @@ -323,7 +322,7 @@ describe('Box', () => { await writeFile(src, 'a'); await box.watch(); box.isWatching().should.be.true; - await Promise.delay(500); + await BluebirdPromise.delay(500); sinonAssert.calledWithMatch(processor.firstCall, { source: src, @@ -346,13 +345,13 @@ describe('Box', () => { box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]); await box.watch(); await appendFile(src, 'b'); - await Promise.delay(500); + await BluebirdPromise.delay(500); sinonAssert.calledWithMatch(processor.lastCall, { source: src, @@ -375,13 +374,13 @@ describe('Box', () => { box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]); await box.watch(); await unlink(src); - await Promise.delay(500); + await BluebirdPromise.delay(500); sinonAssert.calledWithMatch(processor.lastCall, { source: src, @@ -406,13 +405,13 @@ describe('Box', () => { box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]); await box.watch(); await rename(src, newSrc); - await Promise.delay(500); + await BluebirdPromise.delay(500); for (const [file] of processor.args.slice(-2)) { switch (file.type) { @@ -444,13 +443,13 @@ describe('Box', () => { box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]); await box.watch(); await rename(join(box.base, 'a'), join(box.base, 'b')); - await Promise.delay(500); + await BluebirdPromise.delay(500); for (const [file] of processor.args.slice(-2)) { switch (file.type) { @@ -483,17 +482,17 @@ describe('Box', () => { box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src1, 'a'), Cache.insert({_id: cacheId1}) ]); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src2, 'b'), Cache.insert({_id: cacheId2}) ]); await box.watch(); await appendFile(src1, 'aaa'); - await Promise.delay(500); + await BluebirdPromise.delay(500); const file = processor.lastCall.args[0]; @@ -505,7 +504,7 @@ describe('Box', () => { }); await appendFile(src2, 'bbb'); - await Promise.delay(500); + await BluebirdPromise.delay(500); const file2 = processor.lastCall.args[0]; file2.should.eql(file); // not changed @@ -530,21 +529,21 @@ describe('Box', () => { box.addProcessor(processor); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src1, 'a'), Cache.insert({_id: cacheId1}) ]); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src2, 'b'), Cache.insert({_id: cacheId2}) ]); - await Promise.all([ + await BluebirdPromise.all([ writeFile(src3, 'c'), Cache.insert({_id: cacheId3}) ]); await box.watch(); await appendFile(src1, 'aaa'); - await Promise.delay(500); + await BluebirdPromise.delay(500); const file = processor.lastCall.args[0]; @@ -556,12 +555,12 @@ describe('Box', () => { }); await appendFile(src2, 'bbb'); - await Promise.delay(500); + await BluebirdPromise.delay(500); processor.lastCall.args[0].should.eql(file); // not changed await appendFile(src3, 'ccc'); - await Promise.delay(500); + await BluebirdPromise.delay(500); processor.lastCall.args[0].should.eql(file); // not changed @@ -591,7 +590,7 @@ describe('Box', () => { data.push(file.path); }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(join(box.base, 'a.txt'), 'a'), writeFile(join(box.base, 'b', 'c.js'), 'c') ]); diff --git a/test/scripts/console/config.ts b/test/scripts/console/config.ts index 0a70da3c73..8dc26b75ca 100644 --- a/test/scripts/console/config.ts +++ b/test/scripts/console/config.ts @@ -57,8 +57,7 @@ describe('config', () => { await config({_: ['server.port']}); sinonAssert.calledWith(logStub, (hexo.config as any).server.port); } finally { - // @ts-ignore - delete hexo.config.server; + delete(hexo.config as any).server; logStub.restore(); } }); diff --git a/test/scripts/console/deploy.ts b/test/scripts/console/deploy.ts index efcb98f5d4..fb8f291d45 100644 --- a/test/scripts/console/deploy.ts +++ b/test/scripts/console/deploy.ts @@ -25,8 +25,7 @@ describe('deploy', () => { after(() => rmdir(hexo.base_dir)); it('no deploy config', () => { - // @ts-ignore - delete hexo.config.deploy; + delete(hexo.config as any).deploy; const logStub = stub(console, 'log'); diff --git a/test/scripts/console/generate.ts b/test/scripts/console/generate.ts index bf6a04615e..0ab3e6c191 100644 --- a/test/scripts/console/generate.ts +++ b/test/scripts/console/generate.ts @@ -1,7 +1,6 @@ import { join } from 'path'; import { emptyDir, exists, mkdirs, readFile, rmdir, stat, unlink, writeFile } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { spy } from 'sinon'; import chai from 'chai'; const should = chai.should(); @@ -30,7 +29,7 @@ describe('generate', () => { }); const testGenerate = async (options?: any) => { - await Promise.all([ + await BluebirdPromise.all([ // Add some source files writeFile(join(hexo.source_dir, 'test.txt'), 'test'), writeFile(join(hexo.source_dir, 'faz', 'yo.txt'), 'yoooo'), @@ -41,7 +40,7 @@ describe('generate', () => { ]); await generate(options); - const result = await Promise.all([ + const result = await BluebirdPromise.all([ readFile(join(hexo.public_dir, 'test.txt')), readFile(join(hexo.public_dir, 'faz', 'yo.txt')), exists(join(hexo.public_dir, 'foo.txt')), @@ -59,7 +58,7 @@ describe('generate', () => { it('default', () => testGenerate()); it('public_dir is not a directory', async () => { - await Promise.all([ + await BluebirdPromise.all([ // Add some source files writeFile(join(hexo.source_dir, 'test.txt'), 'test'), // Add some files to public folder @@ -97,7 +96,7 @@ describe('generate', () => { result.should.eql(content); // Remove source files and generated files - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); @@ -128,7 +127,7 @@ describe('generate', () => { result.should.eql(newContent); // Remove source files and generated files - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); @@ -148,7 +147,7 @@ describe('generate', () => { let stats = await stat(dest); const mtime = stats.mtime.getTime(); - await Promise.delay(1000); + await BluebirdPromise.delay(1000); // Force regenerate await generate({ force: true }); @@ -157,7 +156,7 @@ describe('generate', () => { stats.mtime.getTime().should.above(mtime); // Remove source files and generated files - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); @@ -173,7 +172,7 @@ describe('generate', () => { // Update the file await writeFile(src, content); - await Promise.delay(300); + await BluebirdPromise.delay(300); // Check the updated file const result = await readFile(dest); @@ -199,7 +198,7 @@ describe('generate', () => { it('update theme source files', async () => { // Add some source files - await Promise.all([ + await BluebirdPromise.all([ // Add some source files writeFile(join(hexo.theme_dir, 'source', 'a.txt'), 'a'), writeFile(join(hexo.theme_dir, 'source', 'b.txt'), 'b'), @@ -208,7 +207,7 @@ describe('generate', () => { await generate(); // Update source file - await Promise.all([ + await BluebirdPromise.all([ writeFile(join(hexo.theme_dir, 'source', 'b.txt'), 'bb'), writeFile(join(hexo.theme_dir, 'source', 'c.njk'), 'cc') ]); @@ -216,10 +215,10 @@ describe('generate', () => { // Generate again await generate(); - await Promise.delay(300); + await BluebirdPromise.delay(300); // Read the updated source file - const result = await Promise.all([ + const result = await BluebirdPromise.all([ readFile(join(hexo.public_dir, 'b.txt')), readFile(join(hexo.public_dir, 'c.html')) ]); @@ -229,7 +228,7 @@ describe('generate', () => { }); it('proceeds after error when bail option is not set', async () => { - hexo.extend.renderer.register('err', 'html', () => Promise.reject(new Error('Testing unhandled exception'))); + hexo.extend.renderer.register('err', 'html', () => BluebirdPromise.reject(new Error('Testing unhandled exception'))); hexo.extend.generator.register('test_page', () => [ { @@ -245,7 +244,7 @@ describe('generate', () => { }); it('proceeds after error when bail option is set to false', async () => { - hexo.extend.renderer.register('err', 'html', () => Promise.reject(new Error('Testing unhandled exception'))); + hexo.extend.renderer.register('err', 'html', () => BluebirdPromise.reject(new Error('Testing unhandled exception'))); hexo.extend.generator.register('test_page', () => [ { @@ -261,7 +260,7 @@ describe('generate', () => { }); it('breaks after error when bail option is set to true', async () => { - hexo.extend.renderer.register('err', 'html', () => Promise.reject(new Error('Testing unhandled exception'))); + hexo.extend.renderer.register('err', 'html', () => BluebirdPromise.reject(new Error('Testing unhandled exception'))); hexo.extend.generator.register('test_page', () => [ { @@ -295,7 +294,7 @@ describe('generate', () => { }, { path: 'resource-3', - data: () => Promise.resolve(Buffer.from('string')) + data: () => BluebirdPromise.resolve(Buffer.from('string')) } ] ); @@ -322,13 +321,13 @@ describe('generate - watch (delete)', () => { const exist = await exists(hexo.base_dir); if (exist) { await emptyDir(hexo.base_dir); - await Promise.delay(500); + await BluebirdPromise.delay(500); await rmdir(hexo.base_dir); } }); const testGenerate = async options => { - await Promise.all([ + await BluebirdPromise.all([ // Add some source files writeFile(join(hexo.source_dir, 'test.txt'), 'test'), writeFile(join(hexo.source_dir, 'faz', 'yo.txt'), 'yoooo'), @@ -339,7 +338,7 @@ describe('generate - watch (delete)', () => { ]); await generate(options); - const result = await Promise.all([ + const result = await BluebirdPromise.all([ readFile(join(hexo.public_dir, 'test.txt')), readFile(join(hexo.public_dir, 'faz', 'yo.txt')), exists(join(hexo.public_dir, 'foo.txt')), @@ -358,7 +357,7 @@ describe('generate - watch (delete)', () => { await testGenerate({ watch: true }); await unlink(join(hexo.source_dir, 'test.txt')); - await Promise.delay(500); + await BluebirdPromise.delay(500); const exist = await exists(join(hexo.public_dir, 'test.txt')); exist.should.be.false; diff --git a/test/scripts/console/list.ts b/test/scripts/console/list.ts index 0aa0b8ec24..d9353102f1 100644 --- a/test/scripts/console/list.ts +++ b/test/scripts/console/list.ts @@ -1,6 +1,5 @@ import { spy, stub, assert as sinonAssert, SinonSpy } from 'sinon'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import listConsole from '../../../lib/plugins/console/list'; type OriginalParams = Parameters; @@ -24,7 +23,7 @@ describe('Console list', () => { it('has args', async () => { const logStub = stub(console, 'log'); - hexo.load = () => Promise.resolve(); + hexo.load = () => BluebirdPromise.resolve(); const list: (...args: OriginalParams) => OriginalReturn = listConsole.bind(hexo); diff --git a/test/scripts/console/list_categories.ts b/test/scripts/console/list_categories.ts index 2a5d47fb76..6de2ae98b5 100644 --- a/test/scripts/console/list_categories.ts +++ b/test/scripts/console/list_categories.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { stub, assert as sinonAssert } from 'sinon'; import Hexo from '../../../lib/hexo'; import listCategory from '../../../lib/plugins/console/list/category'; @@ -36,7 +35,7 @@ describe('Console list', () => { await hexo.init(); const output = await Post.insert(posts); - await Promise.each([ + await BluebirdPromise.each([ ['foo'], ['baz'], ['baz'] diff --git a/test/scripts/console/list_post.ts b/test/scripts/console/list_post.ts index 72f92a44b1..7b47e170b1 100644 --- a/test/scripts/console/list_post.ts +++ b/test/scripts/console/list_post.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { stub, assert as sinonAssert } from 'sinon'; import Hexo from '../../../lib/hexo'; import listPost from '../../../lib/plugins/console/list/post'; @@ -45,7 +44,7 @@ describe('Console list', () => { await hexo.init(); const output = await Post.insert(posts); - await Promise.each(tags, (tags, i) => output[i].setTags(tags)); + await BluebirdPromise.each(tags, (tags, i) => output[i].setTags(tags)); await hexo.locals.invalidate(); listPosts(); diff --git a/test/scripts/console/list_tags.ts b/test/scripts/console/list_tags.ts index 4be2747913..248a2c0190 100644 --- a/test/scripts/console/list_tags.ts +++ b/test/scripts/console/list_tags.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { stub, assert as sinonAssert } from 'sinon'; import Hexo from '../../../lib/hexo'; import listTag from '../../../lib/plugins/console/list/tag'; @@ -39,7 +38,7 @@ describe('Console list', () => { await hexo.init(); const output = await Post.insert(posts); - await Promise.each([ + await BluebirdPromise.each([ ['foo'], ['baz'], ['baz'] diff --git a/test/scripts/console/new.ts b/test/scripts/console/new.ts index 9ff8fb4bb4..608d6eed7c 100644 --- a/test/scripts/console/new.ts +++ b/test/scripts/console/new.ts @@ -1,8 +1,7 @@ import { exists, mkdirs, readFile, rmdir, unlink } from 'hexo-fs'; import moment from 'moment'; import { join } from 'path'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { useFakeTimers, spy, SinonSpy } from 'sinon'; import Hexo from '../../../lib/hexo'; import newConsole from '../../../lib/plugins/console/new'; @@ -21,7 +20,7 @@ describe('new', () => { await mkdirs(hexo.base_dir); await hexo.init(); - await Promise.all([ + await BluebirdPromise.all([ hexo.scaffold.set('post', [ 'title: {{ title }}', 'date: {{ date }}', @@ -201,7 +200,7 @@ describe('new', () => { const exist = await exists(path); exist.should.be.true; - await Promise.all([ + await BluebirdPromise.all([ unlink(path), unlink(join(hexo.source_dir, '_posts', 'Hello-World.md')) ]); diff --git a/test/scripts/console/publish.ts b/test/scripts/console/publish.ts index afd2dcef7d..2cbb7aaf2f 100644 --- a/test/scripts/console/publish.ts +++ b/test/scripts/console/publish.ts @@ -1,8 +1,7 @@ import { exists, mkdirs, readFile, rmdir, unlink } from 'hexo-fs'; import moment from 'moment'; import { join } from 'path'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { useFakeTimers, spy, SinonSpy, SinonFakeTimers } from 'sinon'; import Hexo from '../../../lib/hexo'; import publishConsole from '../../../lib/plugins/console/publish'; @@ -119,7 +118,7 @@ describe('publish', () => { const exist = await exists(path); exist.should.be.true; - await Promise.all([ + await BluebirdPromise.all([ unlink(path), unlink(join(hexo.source_dir, '_posts', 'Hello-World.md')) ]); diff --git a/test/scripts/console/render.ts b/test/scripts/console/render.ts index 784c5d397e..45d9f52e3a 100644 --- a/test/scripts/console/render.ts +++ b/test/scripts/console/render.ts @@ -1,7 +1,6 @@ import { mkdirs, readFile, rmdir, unlink, writeFile } from 'hexo-fs'; import { join } from 'path'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { spy, SinonSpy } from 'sinon'; import Hexo from '../../../lib/hexo'; import renderConsole from '../../../lib/plugins/console/render'; @@ -51,7 +50,7 @@ describe('render', () => { } }); - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); @@ -72,7 +71,7 @@ describe('render', () => { } }); - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); @@ -93,7 +92,7 @@ describe('render', () => { } }); - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); @@ -116,7 +115,7 @@ describe('render', () => { } }); - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); @@ -137,7 +136,7 @@ describe('render', () => { } }, null, ' ')); - await Promise.all([ + await BluebirdPromise.all([ unlink(src), unlink(dest) ]); diff --git a/test/scripts/extend/console.ts b/test/scripts/extend/console.ts index ab70d3d04a..2633f18575 100644 --- a/test/scripts/extend/console.ts +++ b/test/scripts/extend/console.ts @@ -7,7 +7,7 @@ describe('Console', () => { const c = new Console(); // no name - // @ts-ignore + // @ts-expect-error should.throw(() => c.register(), TypeError, 'name is required'); // name, fn @@ -16,18 +16,18 @@ describe('Console', () => { c.get('test').should.exist; // name, not fn - // @ts-ignore + // @ts-expect-error should.throw(() => c.register('test'), TypeError, 'fn must be a function'); // name, desc, fn c.register('test', 'this is a test', () => {}); c.get('test').should.exist; - // @ts-ignore - c.get('test').desc.should.eql('this is a test'); + + c.get('test').desc!.should.eql('this is a test'); // name, desc, not fn - // @ts-ignore + // @ts-expect-error should.throw(() => c.register('test', 'this is a test'), TypeError, 'fn must be a function'); // name, options, fn @@ -44,7 +44,7 @@ describe('Console', () => { c.get('test').options!.init!.should.be.true; // name, desc, options, not fn - // @ts-ignore + // @ts-expect-error should.throw(() => c.register('test', 'this is a test', {init: true}), TypeError, 'fn must be a function'); }); diff --git a/test/scripts/extend/deployer.ts b/test/scripts/extend/deployer.ts index fc5d096cd2..100f929455 100644 --- a/test/scripts/extend/deployer.ts +++ b/test/scripts/extend/deployer.ts @@ -12,11 +12,11 @@ describe('Deployer', () => { d.get('test').should.exist; // no name - // @ts-ignore + // @ts-expect-error should.throw(() => d.register(), TypeError, 'name is required'); // no fn - // @ts-ignore + // @ts-expect-error should.throw(() => d.register('test'), TypeError, 'fn must be a function'); }); diff --git a/test/scripts/extend/filter.ts b/test/scripts/extend/filter.ts index a7f5adf0f0..015f69d9ba 100644 --- a/test/scripts/extend/filter.ts +++ b/test/scripts/extend/filter.ts @@ -30,7 +30,7 @@ describe('Filter', () => { f.list('after_post_render')[1].priority!.should.eql(50); // no fn - // @ts-ignore + // @ts-expect-error should.throw(() => f.register(), TypeError, 'fn must be a function'); }); @@ -73,13 +73,13 @@ describe('Filter', () => { it('unregister() - type is required', () => { const f = new Filter(); - // @ts-ignore + // @ts-expect-error should.throw(() => f.unregister(), 'type is required'); }); it('unregister() - fn must be a function', () => { const f = new Filter(); - // @ts-ignore + // @ts-expect-error should.throw(() => f.unregister('test'), 'fn must be a function'); }); diff --git a/test/scripts/extend/generator.ts b/test/scripts/extend/generator.ts index 37325838b6..f227e7fe0d 100644 --- a/test/scripts/extend/generator.ts +++ b/test/scripts/extend/generator.ts @@ -17,7 +17,7 @@ describe('Generator', () => { g.get('generator-0').should.exist; // no fn - // @ts-ignore + // @ts-expect-error should.throw(() => g.register('test'), TypeError, 'fn must be a function'); }); diff --git a/test/scripts/extend/helper.ts b/test/scripts/extend/helper.ts index 2bb5152c66..8664446748 100644 --- a/test/scripts/extend/helper.ts +++ b/test/scripts/extend/helper.ts @@ -12,11 +12,11 @@ describe('Helper', () => { h.get('test').should.exist; // no fn - // @ts-ignore + // @ts-expect-error should.throw(() => h.register('test'), TypeError, 'fn must be a function'); // no name - // @ts-ignore + // @ts-expect-error should.throw(() => h.register(), TypeError, 'name is required'); }); diff --git a/test/scripts/extend/injector.ts b/test/scripts/extend/injector.ts index 24d7c2106e..64fcccff2d 100644 --- a/test/scripts/extend/injector.ts +++ b/test/scripts/extend/injector.ts @@ -18,7 +18,7 @@ describe('Injector', () => { // no name try { - // @ts-ignore + // @ts-expect-error i.register(); } catch (err) { err.should.be @@ -52,7 +52,7 @@ describe('Injector', () => { const i = new Injector(); const str = ''; - // @ts-ignore + // @ts-expect-error i.register('foo', str); i.get('head_end').should.contains(str); diff --git a/test/scripts/extend/migrator.ts b/test/scripts/extend/migrator.ts index a284e04dae..c1a7ccb73c 100644 --- a/test/scripts/extend/migrator.ts +++ b/test/scripts/extend/migrator.ts @@ -12,11 +12,11 @@ describe('Migrator', () => { d.get('test').should.exist; // no name - // @ts-ignore + // @ts-expect-error should.throw(() => d.register(), TypeError, 'name is required'); // no fn - // @ts-ignore + // @ts-expect-error should.throw(() => d.register('test'), TypeError, 'fn must be a function'); }); diff --git a/test/scripts/extend/processor.ts b/test/scripts/extend/processor.ts index 0a2e5236a8..d67e052fdf 100644 --- a/test/scripts/extend/processor.ts +++ b/test/scripts/extend/processor.ts @@ -17,13 +17,13 @@ describe('Processor', () => { p.list()[1].should.exist; // more than one arg - // @ts-ignore + // @ts-expect-error p.register((a, b) => {}); p.list()[1].should.exist; // no fn - // @ts-ignore + // @ts-expect-error should.throw(() => p.register(), TypeError, 'fn must be a function'); }); diff --git a/test/scripts/extend/renderer.ts b/test/scripts/extend/renderer.ts index f06dd2cbdd..4432ee2aa9 100644 --- a/test/scripts/extend/renderer.ts +++ b/test/scripts/extend/renderer.ts @@ -1,6 +1,5 @@ import Renderer from '../../../lib/extend/renderer'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import chai from 'chai'; const should = chai.should(); @@ -10,7 +9,7 @@ describe('Renderer', () => { const r = new Renderer(); // name, output, fn - r.register('yaml', 'json', () => Promise.resolve()); + r.register('yaml', 'json', () => BluebirdPromise.resolve()); r.get('yaml').should.exist; r.get('yaml').output!.should.eql('json'); @@ -24,15 +23,15 @@ describe('Renderer', () => { r.get('yaml', true).output!.should.eql('json'); // no fn - // @ts-ignore + // @ts-expect-error should.throw(() => r.register('yaml', 'json'), TypeError, 'fn must be a function'); // no output - // @ts-ignore + // @ts-expect-error should.throw(() => r.register('yaml'), TypeError, 'output is required'); // no name - // @ts-ignore + // @ts-expect-error should.throw(() => r.register(), TypeError, 'name is required'); }); @@ -42,7 +41,7 @@ describe('Renderer', () => { // async r.register('yaml', 'json', (_data, _options, callback) => { callback && callback(null, 'foo'); - return Promise.resolve(); + return BluebirdPromise.resolve(); }); const yaml = await r.get('yaml')({}, {}); @@ -59,7 +58,7 @@ describe('Renderer', () => { const r = new Renderer(); function renderer(data, locals) { - return Promise.resolve(); + return BluebirdPromise.resolve(); } renderer.compile = data => { @@ -73,7 +72,7 @@ describe('Renderer', () => { it('getOutput()', () => { const r = new Renderer(); - r.register('yaml', 'json', () => Promise.resolve()); + r.register('yaml', 'json', () => BluebirdPromise.resolve()); r.getOutput('yaml').should.eql('json'); r.getOutput('.yaml').should.eql('json'); @@ -84,7 +83,7 @@ describe('Renderer', () => { it('isRenderable()', () => { const r = new Renderer(); - r.register('yaml', 'json', () => Promise.resolve()); + r.register('yaml', 'json', () => BluebirdPromise.resolve()); r.isRenderable('yaml').should.be.true; r.isRenderable('.yaml').should.be.true; @@ -95,7 +94,7 @@ describe('Renderer', () => { it('isRenderableSync()', () => { const r = new Renderer(); - r.register('yaml', 'json', () => Promise.resolve()); + r.register('yaml', 'json', () => BluebirdPromise.resolve()); r.isRenderableSync('yaml').should.be.false; @@ -110,7 +109,7 @@ describe('Renderer', () => { it('get()', () => { const r = new Renderer(); - r.register('yaml', 'json', () => Promise.resolve()); + r.register('yaml', 'json', () => BluebirdPromise.resolve()); r.get('yaml').should.exist; r.get('.yaml').should.exist; @@ -127,7 +126,7 @@ describe('Renderer', () => { it('list()', () => { const r = new Renderer(); - r.register('yaml', 'json', () => Promise.resolve()); + r.register('yaml', 'json', () => BluebirdPromise.resolve()); r.register('swig', 'html', () => {}, true); diff --git a/test/scripts/extend/tag.ts b/test/scripts/extend/tag.ts index cad5876d18..0407558a86 100644 --- a/test/scripts/extend/tag.ts +++ b/test/scripts/extend/tag.ts @@ -123,12 +123,12 @@ describe('Tag', () => { }); it('register() - name is required', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => tag.register(), 'name is required'); }); it('register() - fn must be a function', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => tag.register('test'), 'fn must be a function'); }); @@ -149,7 +149,7 @@ describe('Tag', () => { }); it('unregister() - name is required', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => tag.unregister(), 'name is required'); }); diff --git a/test/scripts/filters/backtick_code_block.ts b/test/scripts/filters/backtick_code_block.ts index 0dce3c3465..7a048301be 100644 --- a/test/scripts/filters/backtick_code_block.ts +++ b/test/scripts/filters/backtick_code_block.ts @@ -65,10 +65,8 @@ describe('Backtick code block', () => { const oldHljsCfg = hexo.config.highlight; const oldPrismCfg = hexo.config.prismjs; - // @ts-ignore - delete hexo.config.highlight; - // @ts-ignore - delete hexo.config.prismjs; + delete(hexo.config as any).highlight; + delete(hexo.config as any).prismjs; codeBlock(data); data.content.should.eql(content); diff --git a/test/scripts/filters/external_link.ts b/test/scripts/filters/external_link.ts index 414168593c..f0edddbd3f 100644 --- a/test/scripts/filters/external_link.ts +++ b/test/scripts/filters/external_link.ts @@ -127,7 +127,7 @@ describe('External link', () => { 'Hexo' ].join('\n'); - // @ts-ignore + // @ts-expect-error hexo.config.external_link.exclude = ['foo.com', 'bar.com']; const result = externalLink(content); diff --git a/test/scripts/filters/save_database.ts b/test/scripts/filters/save_database.ts index 030b9151cb..34c444f3dc 100644 --- a/test/scripts/filters/save_database.ts +++ b/test/scripts/filters/save_database.ts @@ -1,14 +1,13 @@ import Hexo from '../../../lib/hexo'; import { exists, unlink } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import saveDatabaseFilter from '../../../lib/plugins/filter/before_exit/save_database'; type SaveDatabaseFilterParams = Parameters type SaveDatabaseFilterReturn = ReturnType describe('Save database', () => { const hexo = new Hexo(); - const saveDatabase: (...args: SaveDatabaseFilterParams) => Promise = Promise.method(saveDatabaseFilter).bind(hexo); + const saveDatabase: (...args: SaveDatabaseFilterParams) => BluebirdPromise = BluebirdPromise.method(saveDatabaseFilter).bind(hexo); const dbPath = hexo.database.options.path; it('default', async () => { diff --git a/test/scripts/generators/page.ts b/test/scripts/generators/page.ts index 40acb39c17..16e2911b04 100644 --- a/test/scripts/generators/page.ts +++ b/test/scripts/generators/page.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import pageGenerator from '../../../lib/plugins/generator/page'; import { NormalPostGenerator } from '../../../lib/types'; @@ -11,7 +10,7 @@ type PageGeneratorReturn = ReturnType; describe('page', () => { const hexo = new Hexo(__dirname, {silent: true}); const Page = hexo.model('Page'); - const generator: (...args: PageGeneratorParams) => Promise = Promise.method(pageGenerator.bind(hexo)); + const generator: (...args: PageGeneratorParams) => BluebirdPromise = BluebirdPromise.method(pageGenerator.bind(hexo)); const locals = (): any => { hexo.locals.invalidate(); diff --git a/test/scripts/generators/post.ts b/test/scripts/generators/post.ts index c99fb6922a..59ed7ca238 100644 --- a/test/scripts/generators/post.ts +++ b/test/scripts/generators/post.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import postGenerator from '../../../lib/plugins/generator/post'; import { NormalPostGenerator } from '../../../lib/types'; @@ -11,7 +10,7 @@ type PostGeneratorReturn = ReturnType; describe('post', () => { const hexo = new Hexo(__dirname, {silent: true}); const Post = hexo.model('Post'); - const generator: (...args: PostGeneratorParams) => Promise = Promise.method(postGenerator.bind(hexo)); + const generator: (...args: PostGeneratorParams) => BluebirdPromise = BluebirdPromise.method(postGenerator.bind(hexo)); hexo.config.permalink = ':title/'; @@ -79,6 +78,6 @@ describe('post', () => { data[2].data.prev!._id!.should.eq(posts[0]._id); should.not.exist(data[2].data.next); - await Promise.all(posts.map(post => post.remove())); + await BluebirdPromise.all(posts.map(post => post.remove())); }); }); diff --git a/test/scripts/helpers/date.ts b/test/scripts/helpers/date.ts index f02e8fbaba..f7e8e38e2f 100644 --- a/test/scripts/helpers/date.ts +++ b/test/scripts/helpers/date.ts @@ -236,11 +236,11 @@ describe('date', () => { it('toMomentLocale', () => { (toMomentLocale(undefined) === undefined).should.be.true; // @ts-ignore - toMomentLocale(null).should.eql('en'); - toMomentLocale('').should.eql('en'); - toMomentLocale('en').should.eql('en'); - toMomentLocale('default').should.eql('en'); - toMomentLocale('zh-CN').should.eql('zh-cn'); - toMomentLocale('zh_CN').should.eql('zh-cn'); + toMomentLocale(null)!.should.eql('en'); + toMomentLocale('')!.should.eql('en'); + toMomentLocale('en')!.should.eql('en'); + toMomentLocale('default')!.should.eql('en'); + toMomentLocale('zh-CN')!.should.eql('zh-cn'); + toMomentLocale('zh_CN')!.should.eql('zh-cn'); }); }); diff --git a/test/scripts/helpers/feed_tag.ts b/test/scripts/helpers/feed_tag.ts index 03961a50b9..ba437e2fcb 100644 --- a/test/scripts/helpers/feed_tag.ts +++ b/test/scripts/helpers/feed_tag.ts @@ -39,19 +39,17 @@ describe('feed_tag', () => { }); it('invalid input - number', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => feed(123), 'path must be a string!'); }); it('invalid input - undefined', () => { delete ctx.config.feed; - // @ts-ignore feed().should.eql(''); }); it('invalid input - empty', () => { ctx.config.feed = {}; - // @ts-ignore feed().should.eql(''); }); diff --git a/test/scripts/helpers/partial.ts b/test/scripts/helpers/partial.ts index 85e7dbe35f..3f1d9c314f 100644 --- a/test/scripts/helpers/partial.ts +++ b/test/scripts/helpers/partial.ts @@ -1,7 +1,6 @@ import pathFn from 'path'; import { mkdirs, writeFile, rmdir } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import fragmentCache from '../../../lib/plugins/helper/fragment_cache'; import partialHelper from '../../../lib/plugins/helper/partial'; @@ -32,7 +31,7 @@ describe('partial', () => { const partial: (...args: PartialHelperParams) => PartialHelperReturn = partialHelper(hexo).bind(ctx); before(async () => { - await Promise.all([ + await BluebirdPromise.all([ mkdirs(themeDir), writeFile(hexo.config_path, 'theme: test') ]); @@ -87,7 +86,7 @@ describe('partial', () => { }); it('name must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => partial(), 'name must be a string!'); }); }); diff --git a/test/scripts/helpers/search_form.ts b/test/scripts/helpers/search_form.ts index 7de9cbaecc..4b52eface8 100644 --- a/test/scripts/helpers/search_form.ts +++ b/test/scripts/helpers/search_form.ts @@ -52,7 +52,7 @@ describe('search_form', () => { }); it('button - ignore incorrect type', () => { - // @ts-ignore + // @ts-expect-error searchForm({button: {}, text: 'Find'}).should.eql('
' + '' + '' diff --git a/test/scripts/helpers/tagcloud.ts b/test/scripts/helpers/tagcloud.ts index 3704694ee7..dd7237bbc9 100644 --- a/test/scripts/helpers/tagcloud.ts +++ b/test/scripts/helpers/tagcloud.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import tagcloudHelper from '../../../lib/plugins/helper/tagcloud'; import chai from 'chai'; @@ -27,7 +26,7 @@ describe('tagcloud', () => { {source: 'boo', slug: 'boo'} ]); // TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem - await Promise.all([ + await BluebirdPromise.all([ ['bcd'], ['bcd', 'cde'], ['bcd', 'cde', 'abc'], @@ -53,7 +52,7 @@ describe('tagcloud', () => { const hexo = new Hexo(__dirname); await hexo.init(); hexo.locals.invalidate(); - // @ts-ignore + // @ts-expect-error hexo.site = hexo.locals.toObject(); const tagcloud: (...args: TagcloudHelperParams) => TagcloudHelperReturn = tagcloudHelper.bind(hexo); diff --git a/test/scripts/hexo/hexo.ts b/test/scripts/hexo/hexo.ts index 9dfae90aaf..50b5b2a287 100644 --- a/test/scripts/hexo/hexo.ts +++ b/test/scripts/hexo/hexo.ts @@ -1,7 +1,6 @@ import { sep, join } from 'path'; import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { spy } from 'sinon'; import { readStream } from '../../util'; import { full_url_for } from 'hexo-util'; @@ -168,6 +167,7 @@ describe('Hexo', () => { themeConfig.a.b.should.eql(3); const Locals = hexo._generateLocals(); + // @ts-expect-error const { theme: themeLocals } = new Locals('', {path: '', layout: [], data: {}}); themeLocals.a.should.have.own.property('c'); @@ -187,6 +187,7 @@ describe('Hexo', () => { themeConfig.c.should.eql(3); const Locals = hexo._generateLocals(); + // @ts-expect-error const { theme: themeLocals } = new Locals('', {path: '', layout: [], data: {}}); themeLocals.should.have.own.property('c'); @@ -229,7 +230,7 @@ describe('Hexo', () => { await hexo.watch(); await checkStream(route.get('test.txt'), body); // Test for first generation await writeFile(target, newBody); // Update the file - await Promise.delay(300); + await BluebirdPromise.delay(300); await checkStream(route.get('test.txt'), newBody); // Check the new route hexo.unwatch(); // Stop watching await unlink(target); // Delete the file @@ -298,9 +299,9 @@ describe('Hexo', () => { }); it('exit() - error handling - promise', () => { - return Promise.all([ + return BluebirdPromise.all([ hexo.exit({ foo: 'bar' }), - new Promise((resolve, reject) => { + new BluebirdPromise((resolve, reject) => { hexo.once('exit', err => { try { err.should.eql({ foo: 'bar' }); @@ -431,7 +432,7 @@ describe('Hexo', () => { beforeHook.calledOnce.should.be.true; afterHook.calledOnce.should.be.true; - await Promise.all([ + await BluebirdPromise.all([ checkStream(route.get('foo'), 'foo'), checkStream(route.get('bar'), 'bar'), checkStream(route.get('baz'), 'baz') @@ -531,7 +532,7 @@ describe('Hexo', () => { }); it('_generate() - return nothing in generator', async () => { - // @ts-ignore + // @ts-expect-error hexo.extend.generator.register('test_nothing', () => { // }); @@ -673,7 +674,7 @@ describe('Hexo', () => { it('execFilter() - promise', async () => { const fn = str => { - return new Promise((resolve, reject) => { + return new BluebirdPromise((resolve, reject) => { resolve(str + 'bar'); }); }; diff --git a/test/scripts/hexo/load_plugins.ts b/test/scripts/hexo/load_plugins.ts index 3446114e7e..aece55695f 100644 --- a/test/scripts/hexo/load_plugins.ts +++ b/test/scripts/hexo/load_plugins.ts @@ -2,8 +2,7 @@ import { join, dirname } from 'path'; import { writeFile, mkdir, rmdir, unlink } from 'hexo-fs'; import Hexo from '../../../lib/hexo'; import loadPlugins from '../../../lib/hexo/load_plugins'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import chai from 'chai'; const should = chai.should(); @@ -85,7 +84,7 @@ describe('Load plugins', () => { const name = 'hexo-plugin-test'; const path = join(hexo.plugin_dir, name, 'index.js'); - return Promise.all([ + return BluebirdPromise.all([ createPackageFile(name), writeFile(path, script) ]).then(() => loadPlugins(hexo)).then(() => { @@ -98,7 +97,7 @@ describe('Load plugins', () => { const name = 'hexo-async-plugin-test'; const path = join(hexo.plugin_dir, name, 'index.js'); - return Promise.all([ + return BluebirdPromise.all([ createPackageFile(name), writeFile(path, asyncScript) ]).then(() => loadPlugins(hexo)).then(() => { @@ -111,7 +110,7 @@ describe('Load plugins', () => { const name = '@some-scope/hexo-plugin-test'; const path = join(hexo.plugin_dir, name, 'index.js'); - return Promise.all([ + return BluebirdPromise.all([ createPackageFile(name), writeFile(path, script) ]).then(() => loadPlugins(hexo)).then(() => { @@ -124,7 +123,7 @@ describe('Load plugins', () => { const name = 'hexo-plugin-test'; const path = join(hexo.plugin_dir, name, 'index.js'); - return Promise.all([ + return BluebirdPromise.all([ createPackageFileWithDevDeps(name), writeFile(path, script) ]).then(() => loadPlugins(hexo)).then(() => { @@ -136,7 +135,7 @@ describe('Load plugins', () => { it('load plugins in the theme\'s package.json', async () => { const name = 'hexo-plugin-test'; const path = join(hexo.plugin_dir, name, 'index.js'); - return Promise.all([ + return BluebirdPromise.all([ createPackageFile(name, join(hexo.theme_dir, 'package.json')), writeFile(path, script) ]).then(() => loadPlugins(hexo)).then(() => { @@ -150,7 +149,7 @@ describe('Load plugins', () => { const name = 'hexo-theme-test_theme'; const path = join(hexo.plugin_dir, name, 'index.js'); - await Promise.all([ + await BluebirdPromise.all([ createPackageFile(name), writeFile(path, script) ]); @@ -166,7 +165,7 @@ describe('Load plugins', () => { const name = '@hexojs/hexo-theme-test_theme'; const path = join(hexo.plugin_dir, name, 'index.js'); - await Promise.all([ + await BluebirdPromise.all([ createPackageFile(name), writeFile(path, script) ]); @@ -182,7 +181,7 @@ describe('Load plugins', () => { const name = 'another-plugin'; const path = join(hexo.plugin_dir, name, 'index.js'); - await Promise.all([ + await BluebirdPromise.all([ createPackageFile(name), writeFile(path, script) ]); @@ -197,7 +196,7 @@ describe('Load plugins', () => { const name = '@types/hexo-test-plugin'; const path = join(hexo.plugin_dir, name, 'index.js'); - return Promise.all([ + return BluebirdPromise.all([ createPackageFile(name), writeFile(path, script) ]).then(() => loadPlugins(hexo)).then(() => { diff --git a/test/scripts/hexo/locals.ts b/test/scripts/hexo/locals.ts index 3fb483aef6..b28a2990b7 100644 --- a/test/scripts/hexo/locals.ts +++ b/test/scripts/hexo/locals.ts @@ -6,7 +6,7 @@ describe('Locals', () => { const locals = new Locals(); it('get() - name must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => locals.get(), 'name must be a string!'); }); @@ -26,12 +26,12 @@ describe('Locals', () => { }); it('set() - name must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => locals.set(), 'name must be a string!'); }); it('set() - value is required', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => locals.set('test'), 'value is required!'); }); @@ -45,7 +45,7 @@ describe('Locals', () => { }); it('remove() - name must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => locals.remove(), 'name must be a string!'); }); diff --git a/test/scripts/hexo/render.ts b/test/scripts/hexo/render.ts index b13a9d13f8..01e9cb2632 100644 --- a/test/scripts/hexo/render.ts +++ b/test/scripts/hexo/render.ts @@ -97,7 +97,7 @@ describe('Render', () => { it('render() - no path and text', async () => { try { - // @ts-ignore + // @ts-expect-error await hexo.render.render(); should.fail('Return value must be rejected'); } catch (err) { @@ -236,7 +236,7 @@ describe('Render', () => { }); it('renderSync() - no path and text', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => hexo.render.renderSync(), 'No input file or string!'); }); @@ -298,7 +298,7 @@ describe('Render', () => { const result = hexo.render.renderSync(data); filter.calledOnce.should.be.true; - // @ts-ignore + // @ts-expect-error sinonAssert.calledWith(filter, data.text, data); result.should.eql(data.text.trim()); diff --git a/test/scripts/hexo/router.ts b/test/scripts/hexo/router.ts index 5683a13636..8564500753 100644 --- a/test/scripts/hexo/router.ts +++ b/test/scripts/hexo/router.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { Readable } from 'stream'; import { join } from 'path'; import crypto from 'crypto'; @@ -20,7 +19,7 @@ describe('Router', () => { } function checksum(stream) { - return new Promise((resolve, reject) => { + return new BluebirdPromise((resolve, reject) => { const hash = crypto.createHash('sha1'); stream.on('readable', () => { @@ -58,7 +57,7 @@ describe('Router', () => { }); it('format() - path must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => router.format(() => {}), 'path must be a string!'); }); @@ -111,12 +110,12 @@ describe('Router', () => { }); it('set() - path must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => router.set(), 'path must be a string!'); }); it('set() - data is required', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => router.set('test'), 'data is required!'); }); @@ -154,7 +153,7 @@ describe('Router', () => { router.set('test', () => createReadStream(path)); - return Promise.all([ + return BluebirdPromise.all([ checksum(router.get('test')), checksum(createReadStream(path)) ]).then((data: any) => { @@ -163,7 +162,7 @@ describe('Router', () => { }); it('get() - path must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => router.get(), 'path must be a string!'); }); @@ -192,7 +191,7 @@ describe('Router', () => { }); it('isModified() - path must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => router.isModified(), 'path must be a string!'); }); @@ -209,7 +208,7 @@ describe('Router', () => { }); it('remove() - path must be a string', () => { - // @ts-ignore + // @ts-expect-error should.throw(() => router.remove(), 'path must be a string!'); }); }); diff --git a/test/scripts/hexo/validate_config.ts b/test/scripts/hexo/validate_config.ts index c414c2a68d..87ec01d90e 100644 --- a/test/scripts/hexo/validate_config.ts +++ b/test/scripts/hexo/validate_config.ts @@ -17,8 +17,7 @@ describe('Validate config', () => { }); it('config.url - undefined', () => { - // @ts-ignore - delete hexo.config.url; + delete(hexo.config as any).url; try { validateConfig(hexo); @@ -30,7 +29,7 @@ describe('Validate config', () => { }); it('config.url - wrong type', () => { - // @ts-ignore + // @ts-expect-error hexo.config.url = true; try { @@ -68,8 +67,7 @@ describe('Validate config', () => { }); it('config.root - undefined', () => { - // @ts-ignore - delete hexo.config.root; + delete(hexo.config as any).root; try { validateConfig(hexo); @@ -81,7 +79,7 @@ describe('Validate config', () => { }); it('config.root - wrong type', () => { - // @ts-ignore + // @ts-expect-error hexo.config.root = true; try { diff --git a/test/scripts/models/moment.ts b/test/scripts/models/moment.ts index 19fa102b81..f675d93150 100644 --- a/test/scripts/models/moment.ts +++ b/test/scripts/models/moment.ts @@ -50,7 +50,7 @@ describe('SchemaTypeMoment', () => { it('validate() - required', () => { const type = new SchemaTypeMoment('test', {required: true}); - // @ts-ignore + // @ts-expect-error should.throw(() => type.validate(), '`test` is required!'); }); @@ -70,7 +70,7 @@ describe('SchemaTypeMoment', () => { }); it('parse()', () => { - type.parse('2014-11-03T07:45:41.237Z').should.eql(moment('2014-11-03T07:45:41.237Z')); + type.parse('2014-11-03T07:45:41.237Z')!.should.eql(moment('2014-11-03T07:45:41.237Z')); should.not.exist(type.parse()); }); diff --git a/test/scripts/models/post.ts b/test/scripts/models/post.ts index 258d5dac6e..6c02b54246 100644 --- a/test/scripts/models/post.ts +++ b/test/scripts/models/post.ts @@ -1,6 +1,5 @@ import { join, sep } from 'path'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { full_url_for } from 'hexo-util'; import Hexo from '../../../lib/hexo'; import chai from 'chai'; @@ -239,7 +238,7 @@ describe('Post', () => { it('setTags() - sync problem', () => Post.insert([ {source: 'foo.md', slug: 'foo'}, {source: 'bar.md', slug: 'bar'} - ]).then(posts => Promise.all([ + ]).then(posts => BluebirdPromise.all([ posts[0].setTags(['foo', 'bar']), posts[1].setTags(['bar', 'baz']) ]).thenReturn(posts)).then(posts => { @@ -306,7 +305,7 @@ describe('Post', () => { postA.categories.map(cat => cat._id).should.eql(postB.categories.map(cat => cat._id)); - return Promise.all([ + return BluebirdPromise.all([ Post.removeById(postIdA), Post.removeById(postIdB) ]); @@ -344,7 +343,7 @@ describe('Post', () => { postCategoriesA.should.not.include(catId); }); - return Promise.all([ + return BluebirdPromise.all([ Post.removeById(postIdA), Post.removeById(postIdB) ]); @@ -446,7 +445,7 @@ describe('Post', () => { it('remove related assets when a post is removed', () => Post.insert({ source: 'foo.md', slug: 'bar' - }).then(post => Promise.all([ + }).then(post => BluebirdPromise.all([ Asset.insert({_id: 'foo', path: 'foo'}), Asset.insert({_id: 'bar', path: 'bar'}), Asset.insert({_id: 'baz', path: 'bar'}) diff --git a/test/scripts/processors/common.ts b/test/scripts/processors/common.ts index 444b073c7f..ed07d371ac 100644 --- a/test/scripts/processors/common.ts +++ b/test/scripts/processors/common.ts @@ -33,11 +33,11 @@ describe('common', () => { const d = new Date(); should.not.exist(toDate()); - toDate(m).should.eql(m); - toDate(d).should.eql(d); - toDate(1e8).should.eql(new Date(1e8)); - toDate('2014-04-25T01:32:21.196Z').should.eql(new Date('2014-04-25T01:32:21.196Z')); - toDate('Apr 24 2014').should.eql(new Date(2014, 3, 24)); + toDate(m)!.should.eql(m); + toDate(d)!.should.eql(d); + toDate(1e8)!.should.eql(new Date(1e8)); + toDate('2014-04-25T01:32:21.196Z')!.should.eql(new Date('2014-04-25T01:32:21.196Z')); + toDate('Apr 24 2014')!.should.eql(new Date(2014, 3, 24)); should.not.exist(toDate('foo')); }); diff --git a/test/scripts/processors/data.ts b/test/scripts/processors/data.ts index 95687afce9..0c08476d6d 100644 --- a/test/scripts/processors/data.ts +++ b/test/scripts/processors/data.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs'; import { join } from 'path'; import Hexo from '../../../lib/hexo'; @@ -11,7 +10,7 @@ describe('data', () => { const baseDir = join(__dirname, 'data_test'); const hexo = new Hexo(baseDir); const processor = data(hexo); - const process = Promise.method(processor.process).bind(hexo); + const process = BluebirdPromise.method(processor.process).bind(hexo); const { source } = hexo; const { File } = source; const Data = hexo.model('Data'); @@ -114,7 +113,7 @@ describe('data', () => { type: 'update' }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, body), Data.insert({ _id: 'users', diff --git a/test/scripts/processors/post.ts b/test/scripts/processors/post.ts index e3f1ff54c0..291db2354b 100644 --- a/test/scripts/processors/post.ts +++ b/test/scripts/processors/post.ts @@ -1,8 +1,7 @@ import { join } from 'path'; import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import defaultConfig from '../../../lib/hexo/default_config'; import Hexo from '../../../lib/hexo'; import posts from '../../../lib/plugins/processor/post'; @@ -17,7 +16,7 @@ describe('post', () => { const baseDir = join(__dirname, 'post_test'); const hexo = new Hexo(baseDir); const post = posts(hexo); - const process: (...args: PostParams) => Promise = Promise.method(post.process.bind(hexo)); + const process: (...args: PostParams) => BluebirdPromise = BluebirdPromise.method(post.process.bind(hexo)); const { pattern } = post; const { source } = hexo; const { File } = source; @@ -149,7 +148,7 @@ describe('post', () => { asset.modified.should.be.true; asset.renderable.should.be.false; - await Promise.all([ + await BluebirdPromise.all([ Post.removeById(postId), unlink(file.source) ]); @@ -184,7 +183,7 @@ describe('post', () => { const asset = PostAsset.findById(id); asset.modified.should.be.true; - await Promise.all([ + await BluebirdPromise.all([ Post.removeById(postId), unlink(file.source) ]); @@ -219,7 +218,7 @@ describe('post', () => { const asset = PostAsset.findById(id); asset.modified.should.be.false; - await Promise.all([ + await BluebirdPromise.all([ Post.removeById(postId), unlink(file.source) ]); @@ -311,7 +310,7 @@ describe('post', () => { const id = 'source/' + file.path; - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, 'test'), PostAsset.insert({ _id: id, @@ -353,7 +352,7 @@ describe('post', () => { post.slug.should.eql('foo'); post.published.should.be.true; - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -382,7 +381,7 @@ describe('post', () => { post._id!.should.eql(id); post.title.should.eql('New world'); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -468,7 +467,7 @@ describe('post', () => { post.slug.should.eql('foo'); post.date.format('YYYY-MM-DD').should.eql('2006-01-02'); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -496,7 +495,7 @@ describe('post', () => { post.slug.should.eql('20060102'); post.date.format('YYYY-MM-DD').should.eql('2006-01-02'); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -523,7 +522,7 @@ describe('post', () => { post.lang.should.eql('zh'); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -550,7 +549,7 @@ describe('post', () => { post.slug.should.eql('foo'); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -576,7 +575,7 @@ describe('post', () => { post.published.should.be.false; - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -602,7 +601,7 @@ describe('post', () => { post.published.should.be.false; - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -629,7 +628,7 @@ describe('post', () => { post.date.toDate().setMilliseconds(0).should.eql(stats.birthtime.setMilliseconds(0)); post.updated.toDate().setMilliseconds(0).should.eql(stats.mtime.setMilliseconds(0)); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -659,7 +658,7 @@ describe('post', () => { post.updated.toDate().setMilliseconds(0).should.eql(post.date.toDate().setMilliseconds(0)); post.updated.toDate().setMilliseconds(0).should.not.eql(stats.mtime.setMilliseconds(0)); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -689,7 +688,7 @@ describe('post', () => { post.updated.toDate().setMilliseconds(0).should.eql(stats.mtime.setMilliseconds(0)); post.updated.toDate().setMilliseconds(0).should.not.eql(post.date.toDate().setMilliseconds(0)); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -716,7 +715,7 @@ describe('post', () => { should.not.exist(post.updated); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -749,7 +748,7 @@ describe('post', () => { should.not.exist(post.photo); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -777,7 +776,7 @@ describe('post', () => { 'https://hexo.io/foo.jpg' ]); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -799,7 +798,7 @@ describe('post', () => { post.title.should.eql(''); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -854,7 +853,7 @@ describe('post', () => { should.not.exist(post.category); post.categories.map(item => item.name).should.eql(['foo', 'bar']); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -880,7 +879,7 @@ describe('post', () => { post.categories.map(item => item.name).should.eql(['foo']); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -908,7 +907,7 @@ describe('post', () => { post.categories.map(item => item.name).should.eql(['foo', 'bar', 'baz']); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -937,7 +936,7 @@ describe('post', () => { should.not.exist(post.tag); post.tags.map(item => item.name).should.have.members(['foo', 'bar']); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -963,7 +962,7 @@ describe('post', () => { post.tags.map(item => item.name).should.eql(['foo']); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -1002,7 +1001,7 @@ describe('post', () => { }; }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, body), ...assetFiles.map(obj => writeFile(obj.path, obj.contents)) ]); @@ -1026,7 +1025,7 @@ describe('post', () => { post.remove(); - await Promise.all([ + await BluebirdPromise.all([ unlink(file.source), ...assetFiles.map(obj => unlink(obj.path)) ]); @@ -1051,7 +1050,7 @@ describe('post', () => { const assetId = 'source/_posts/foo/bar.jpg'; const assetPath = join(hexo.base_dir, assetId); - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, body), writeFile(assetPath, '') ]); @@ -1071,7 +1070,7 @@ describe('post', () => { hexo.config.render_drafts = false; - await Promise.all([ + await BluebirdPromise.all([ post.remove(), unlink(file.source), unlink(assetPath) @@ -1097,7 +1096,7 @@ describe('post', () => { const assetId = 'source/_posts/foo/bar.jpg'; const assetPath = join(hexo.base_dir, assetId); - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, body), writeFile(assetPath, '') ]); @@ -1115,7 +1114,7 @@ describe('post', () => { post.published.should.be.false; should.not.exist(PostAsset.findById(assetId)); - await Promise.all([ + await BluebirdPromise.all([ post.remove(), unlink(file.source), unlink(assetPath) @@ -1135,7 +1134,7 @@ describe('post', () => { const assetId = 'source/_posts/foo/bar.jpg'; const assetPath = join(hexo.base_dir, assetId); - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, ''), writeFile(assetPath, '') ]); @@ -1144,7 +1143,7 @@ describe('post', () => { should.not.exist(PostAsset.findById(assetId)); post.remove(); - await Promise.all([ + await BluebirdPromise.all([ unlink(file.source), unlink(assetPath) ]); @@ -1172,7 +1171,7 @@ describe('post', () => { post.date.format(dateFormat).should.eql('2014-04-24 00:00:00'); post.updated.format(dateFormat).should.eql('2015-05-05 00:00:00'); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -1201,7 +1200,7 @@ describe('post', () => { post.date.toDate().setMilliseconds(0).should.eql(stats.birthtime.setMilliseconds(0)); post.updated.toDate().setMilliseconds(0).should.eql(stats.mtime.setMilliseconds(0)); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -1282,7 +1281,7 @@ describe('post', () => { post.__permalink.should.eql('foooo'); - return Promise.all([ + return BluebirdPromise.all([ post.remove(), unlink(file.source) ]); @@ -1304,7 +1303,7 @@ describe('post', () => { type: 'create' }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, 'test'), writeFile(assetFile.source, 'test') ]); @@ -1315,7 +1314,7 @@ describe('post', () => { hexo.config.post_asset_folder = false; - return Promise.all([ + return BluebirdPromise.all([ unlink(file.source), unlink(assetFile.source), post.remove(), @@ -1340,7 +1339,7 @@ describe('post', () => { type: 'create' }); - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, 'test'), writeFile(assetFile.source, 'test') ]); @@ -1352,7 +1351,7 @@ describe('post', () => { hexo.config.post_asset_folder = false; hexo.config.skip_render = '' as any; - return Promise.all([ + return BluebirdPromise.all([ unlink(file.source), unlink(assetFile.source), post.remove(), diff --git a/test/scripts/tags/asset_img.ts b/test/scripts/tags/asset_img.ts index 78e841b1d2..4f4a2a74c2 100644 --- a/test/scripts/tags/asset_img.ts +++ b/test/scripts/tags/asset_img.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import tagAssetImg from '../../../lib/plugins/tag/asset_img'; import chai from 'chai'; @@ -24,7 +23,7 @@ describe('asset_img', () => { })).then(post_ => { post = post_; - return Promise.all([ + return BluebirdPromise.all([ PostAsset.insert({ _id: 'bar', slug: 'bar', diff --git a/test/scripts/tags/asset_link.ts b/test/scripts/tags/asset_link.ts index d03ec1fdb9..3cb73b30b1 100644 --- a/test/scripts/tags/asset_link.ts +++ b/test/scripts/tags/asset_link.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import tagAssetLink from '../../../lib/plugins/tag/asset_link'; import chai from 'chai'; @@ -24,7 +23,7 @@ describe('asset_link', () => { })).then(post_ => { post = post_; - return Promise.all([ + return BluebirdPromise.all([ PostAsset.insert({ _id: 'bar', slug: 'bar', diff --git a/test/scripts/tags/asset_path.ts b/test/scripts/tags/asset_path.ts index ad84a5ff11..2a78f4d2ab 100644 --- a/test/scripts/tags/asset_path.ts +++ b/test/scripts/tags/asset_path.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import tagAssetPath from '../../../lib/plugins/tag/asset_path'; import chai from 'chai'; @@ -24,7 +23,7 @@ describe('asset_path', () => { })).then(post_ => { post = post_; - return Promise.all([ + return BluebirdPromise.all([ PostAsset.insert({ _id: 'bar', slug: 'bar', diff --git a/test/scripts/tags/include_code.ts b/test/scripts/tags/include_code.ts index bbbb37e7fd..62e95b0abe 100644 --- a/test/scripts/tags/include_code.ts +++ b/test/scripts/tags/include_code.ts @@ -1,8 +1,7 @@ import { join } from 'path'; import { rmdir, writeFile } from 'hexo-fs'; import { highlight, prismHighlight } from 'hexo-util'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import tagIncludeCode from '../../../lib/plugins/tag/include_code'; import chai from 'chai'; @@ -11,7 +10,7 @@ const should = chai.should(); describe('include_code', () => { const hexo = new Hexo(join(__dirname, 'include_code_test')); require('../../../lib/plugins/highlight/')(hexo); - const includeCode = Promise.method(tagIncludeCode(hexo)); + const includeCode = BluebirdPromise.method(tagIncludeCode(hexo)) as (arg1: string[]) => BluebirdPromise; const path = join(hexo.source_dir, hexo.config.code_dir, 'test.js'); const defaultCfg = JSON.parse(JSON.stringify(hexo.config)); diff --git a/test/scripts/theme_processors/config.ts b/test/scripts/theme_processors/config.ts index 1a3bdb5b7c..069e6cb1cd 100644 --- a/test/scripts/theme_processors/config.ts +++ b/test/scripts/theme_processors/config.ts @@ -1,8 +1,7 @@ import { spy, assert as sinonAssert } from 'sinon'; import { join } from 'path'; import { mkdirs, rmdir, unlink, writeFile} from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import { config } from '../../../lib/theme/processors/config'; import chai from 'chai'; @@ -12,7 +11,7 @@ type ConfigReturn = ReturnType describe('config', () => { const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); - const process: (...args: ConfigParams) => Promise = Promise.method(config.process.bind(hexo)); + const process: (...args: ConfigParams) => BluebirdPromise = BluebirdPromise.method(config.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); function newFile(options) { @@ -21,7 +20,7 @@ describe('config', () => { } before(async () => { - await Promise.all([ + await BluebirdPromise.all([ mkdirs(themeDir), writeFile(hexo.config_path, 'theme: test') ]); diff --git a/test/scripts/theme_processors/i18n.ts b/test/scripts/theme_processors/i18n.ts index edb1d6b3c4..e4ee9b0417 100644 --- a/test/scripts/theme_processors/i18n.ts +++ b/test/scripts/theme_processors/i18n.ts @@ -1,7 +1,6 @@ import { join } from 'path'; import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import { i18n } from '../../../lib/theme/processors/i18n'; import chai from 'chai'; @@ -11,7 +10,7 @@ type I18nReturn = ReturnType describe('i18n', () => { const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); - const process: (...args: I18nParams) => Promise = Promise.method(i18n.process.bind(hexo)); + const process: (...args: I18nParams) => BluebirdPromise = BluebirdPromise.method(i18n.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); function newFile(options) { @@ -26,7 +25,7 @@ describe('i18n', () => { } before(async () => { - await Promise.all([ + await BluebirdPromise.all([ mkdirs(themeDir), writeFile(hexo.config_path, 'theme: test') ]); diff --git a/test/scripts/theme_processors/source.ts b/test/scripts/theme_processors/source.ts index 9b4f6f2979..a5b73a71b3 100644 --- a/test/scripts/theme_processors/source.ts +++ b/test/scripts/theme_processors/source.ts @@ -1,7 +1,6 @@ import { join } from 'path'; import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import { source } from '../../../lib/theme/processors/source'; import chai from 'chai'; @@ -11,7 +10,7 @@ type SourceReturn = ReturnType describe('source', () => { const hexo = new Hexo(join(__dirname, 'source_test'), {silent: true}); - const process: (...args: SourceParams) => Promise = Promise.method(source.process.bind(hexo)); + const process: (...args: SourceParams) => BluebirdPromise = BluebirdPromise.method(source.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); const Asset = hexo.model('Asset'); @@ -26,7 +25,7 @@ describe('source', () => { } before(async () => { - await Promise.all([ + await BluebirdPromise.all([ mkdirs(themeDir), writeFile(hexo.config_path, 'theme: test') ]); @@ -79,7 +78,7 @@ describe('source', () => { const id = 'themes/test/' + file.path; - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, 'test'), Asset.insert({ _id: id, @@ -92,7 +91,7 @@ describe('source', () => { asset.modified.should.be.true; - await Promise.all([ + await BluebirdPromise.all([ unlink(file.source), Asset.removeById(id) ]); @@ -106,7 +105,7 @@ describe('source', () => { const id = 'themes/test/' + file.path; - await Promise.all([ + await BluebirdPromise.all([ writeFile(file.source, 'test'), Asset.insert({ _id: id, @@ -118,7 +117,7 @@ describe('source', () => { const asset = Asset.findById(id); asset.modified.should.be.false; - await Promise.all([ + await BluebirdPromise.all([ unlink(file.source), Asset.removeById(id) ]); diff --git a/test/scripts/theme_processors/view.ts b/test/scripts/theme_processors/view.ts index 1b7c254af9..2d87a71782 100644 --- a/test/scripts/theme_processors/view.ts +++ b/test/scripts/theme_processors/view.ts @@ -1,7 +1,6 @@ import { join } from 'path'; import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs'; -// @ts-ignore -import Promise from 'bluebird'; +import BluebirdPromise from 'bluebird'; import Hexo from '../../../lib/hexo'; import { view } from '../../../lib/theme/processors/view'; import chai from 'chai'; @@ -12,7 +11,7 @@ type ViewReturn = ReturnType describe('view', () => { const hexo = new Hexo(join(__dirname, 'view_test'), {silent: true}); - const process: (...args: ViewParams) => Promise = Promise.method(view.process.bind(hexo)); + const process: (...args: ViewParams) => BluebirdPromise = BluebirdPromise.method(view.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); hexo.env.init = true; @@ -28,7 +27,7 @@ describe('view', () => { } before(async () => { - await Promise.all([ + await BluebirdPromise.all([ mkdirs(themeDir), writeFile(hexo.config_path, 'theme: test') ]);