Skip to content

Commit 193d10e

Browse files
committed
Add more precise JSDoc for Encore options
This brings the list of supported options in the type definitions with their type, which lets IDEs provide autocompletion for them.
1 parent b31b345 commit 193d10e

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* @import { OptionsCallback } from './lib/utils/apply-options-callback.js'
1818
*/
1919

20+
/**
21+
* @typedef {{from: string, pattern?: RegExp|string, to?: string|null, includeSubdirectories?: boolean, context?: string}} CopyFilesOptions
22+
*/
23+
2024
const EncoreProxy = require('./lib/EncoreProxy');
2125
const WebpackConfig = require('./lib/WebpackConfig');
2226
const configGenerator = require('./lib/config-generator');
@@ -588,7 +592,7 @@ class Encore {
588592
* - {string} context (default: path of the source directory)
589593
* The context to use as a root path when copying files.
590594
*
591-
* @param {object|Array} configs
595+
* @param {CopyFilesOptions|CopyFilesOptions[]} configs
592596
* @returns {Encore}
593597
*/
594598
copyFiles(configs) {
@@ -839,7 +843,7 @@ class Encore {
839843
* // https://www.npmjs.com/package/resolve-url-loader#options
840844
*
841845
* @param {OptionsCallback<object>} sassLoaderOptionsCallback
842-
* @param {object} encoreOptions
846+
* @param {{resolveUrlLoader?: boolean, resolveUrlLoaderOptions?: object}} encoreOptions
843847
* @returns {Encore}
844848
*/
845849
enableSassLoader(sassLoaderOptionsCallback = () => {}, encoreOptions = {}) {
@@ -971,7 +975,7 @@ class Encore {
971975
* if useBuiltIns isn't set to false.
972976
*
973977
* @param {OptionsCallback<object>|null} callback
974-
* @param {object} encoreOptions
978+
* @param {{exclude?: webpack.RuleSetCondition, includeNodeModules?: string[], useBuiltIns?: 'usage' | 'entry' | false, corejs?: number|string|{ version: string, proposals: boolean }|null}} encoreOptions
975979
* @returns {Encore}
976980
*/
977981
configureBabel(callback, encoreOptions = {}) {
@@ -1059,7 +1063,7 @@ class Encore {
10591063
* });
10601064
* ```
10611065
*
1062-
* @param {object} buildDependencies
1066+
* @param {Record<string, string[]>} buildDependencies
10631067
* @param {OptionsCallback<webpack.FileCacheOptions>} cacheCallback
10641068
* @returns {Encore}
10651069
*/
@@ -1125,7 +1129,7 @@ class Encore {
11251129
* Encore.enablePreactPreset({ preactCompat: true })
11261130
* ```
11271131
*
1128-
* @param {object} options
1132+
* @param {{preactCompat?: boolean}} options
11291133
* @returns {Encore}
11301134
*/
11311135
enablePreactPreset(options = {}) {
@@ -1257,7 +1261,7 @@ class Encore {
12571261
* in order to enable JSX usage in Vue components.
12581262
*
12591263
* @param {OptionsCallback<object>} vueLoaderOptionsCallback
1260-
* @param {object} encoreOptions
1264+
* @param {{useJsx?: boolean, version?: number, runtimeCompilerBuild?: boolean}} encoreOptions
12611265
* @returns {Encore}
12621266
*/
12631267
enableVueLoader(vueLoaderOptionsCallback = () => {}, encoreOptions = {}) {
@@ -1387,7 +1391,7 @@ class Encore {
13871391
* which is overridden for both fonts and images. See configureImageRule()
13881392
* and configureFontRule() to control those filenames.
13891393
*
1390-
* @param {object} filenames
1394+
* @param {{js?: string, css?: string, images?: string, fonts?: string}} filenames
13911395
* @returns {Encore}
13921396
*/
13931397
configureFilenames(filenames) {
@@ -1441,7 +1445,7 @@ class Encore {
14411445
* });
14421446
* ```
14431447
*
1444-
* @param {object} options
1448+
* @param {{filename?: string, maxSize?: number|null, type?: string, enabled?: boolean}} options
14451449
* @param {OptionsCallback<webpack.RuleSetRule>} ruleCallback
14461450
* @returns {Encore}
14471451
*/
@@ -1458,7 +1462,7 @@ class Encore {
14581462
*
14591463
* See configureImageRule() for more details.
14601464
*
1461-
* @param {object} options
1465+
* @param {{filename?: string, maxSize?: number|null, type?: string, enabled?: boolean}} options
14621466
* @param {OptionsCallback<webpack.RuleSetRule>} ruleCallback
14631467
* @returns {Encore}
14641468
*/

lib/WebpackConfig.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
* @import { OptionsCallback } from './utils/apply-options-callback.js'
2222
*/
2323

24+
/**
25+
* @import { CopyFilesOptions } from '../index.js'
26+
*/
27+
2428
const path = require('path');
2529
const fs = require('fs');
2630
const crypto = require('crypto');
@@ -80,12 +84,14 @@ class WebpackConfig {
8084
this.cleanupOutput = false;
8185
this.usePersistentCache = false;
8286
this.extractCss = true;
87+
/** @type {{filename: string, maxSize: number|null, type: string, enabled: boolean}} */
8388
this.imageRuleOptions = {
8489
type: 'asset/resource',
8590
maxSize: null,
8691
filename: 'images/[name].[hash:8][ext]',
8792
enabled: true,
8893
};
94+
/** @type {{filename: string, maxSize: number|null, type: string, enabled: boolean}} */
8995
this.fontRuleOptions = {
9096
type: 'asset/resource',
9197
maxSize: null,
@@ -109,13 +115,17 @@ class WebpackConfig {
109115

110116
// Features/Loaders options
111117
this.copyFilesConfigs = [];
118+
/**
119+
* @type {{resolveUrlLoader: boolean, resolveUrlLoaderOptions: object}}
120+
*/
112121
this.sassOptions = {
113122
resolveUrlLoader: true,
114123
resolveUrlLoaderOptions: {}
115124
};
116125
this.preactOptions = {
117126
preactCompat: false
118127
};
128+
/** @type {{exclude: webpack.RuleSetCondition, useBuiltIns: 'usage'|'entry'|false, corejs: number|string|{ version: string, proposals: boolean }|null}} */
119129
this.babelOptions = {
120130
exclude: /(node_modules|bower_components)/,
121131
useBuiltIns: false,
@@ -127,6 +137,7 @@ class WebpackConfig {
127137
version: null,
128138
runtimeCompilerBuild: null
129139
};
140+
/** @type {Record<string, string[]>} */
130141
this.persistentCacheBuildDependencies = {};
131142

132143
// Features/Loaders options callbacks
@@ -428,7 +439,7 @@ class WebpackConfig {
428439

429440
/**
430441
* @param {OptionsCallback<object>|null} callback
431-
* @param {object} options
442+
* @param {{exclude?: webpack.RuleSetCondition, includeNodeModules?: string[], useBuiltIns?: 'usage' | 'entry' | false, corejs?: number|string|{ version: string, proposals: boolean }|null}} options
432443
*/
433444
configureBabel(callback, options = {}) {
434445
if (callback) {
@@ -590,6 +601,10 @@ class WebpackConfig {
590601
this.devServerOptionsConfigurationCallback = callback;
591602
}
592603

604+
/**
605+
* @param {string} name
606+
* @param {object} options
607+
*/
593608
addCacheGroup(name, options) {
594609
if (typeof name !== 'string') {
595610
throw new Error('Argument 1 to addCacheGroup() must be a string.');
@@ -620,6 +635,9 @@ class WebpackConfig {
620635
this.cacheGroups[name] = options;
621636
}
622637

638+
/**
639+
* @param {CopyFilesOptions|CopyFilesOptions[]} configs
640+
*/
623641
copyFiles(configs = []) {
624642
if (!Array.isArray(configs)) {
625643
configs = [configs];
@@ -683,7 +701,7 @@ class WebpackConfig {
683701

684702
/**
685703
* @param {OptionsCallback<object>} sassLoaderOptionsCallback
686-
* @param {object} options
704+
* @param {{resolveUrlLoader?: boolean, resolveUrlLoaderOptions?: object}} options
687705
*/
688706
enableSassLoader(sassLoaderOptionsCallback = () => {}, options = {}) {
689707
this.useSassLoader = true;
@@ -750,7 +768,7 @@ class WebpackConfig {
750768
}
751769

752770
/**
753-
* @param {object} buildDependencies
771+
* @param {Record<string, string[]>} buildDependencies
754772
* @param {OptionsCallback<webpack.FileCacheOptions>} callback
755773
*/
756774
enableBuildCache(buildDependencies, callback = (cache) => {}) {
@@ -916,7 +934,7 @@ class WebpackConfig {
916934
}
917935

918936
/**
919-
* @param {object} options
937+
* @param {{filename?: string, maxSize?: number|null, type?: string, enabled?: boolean}} options
920938
* @param {OptionsCallback<webpack.RuleSetRule>} ruleCallback
921939
*/
922940
configureImageRule(options = {}, ruleCallback = () => {}) {
@@ -940,7 +958,7 @@ class WebpackConfig {
940958
}
941959

942960
/**
943-
* @param {object} options
961+
* @param {{filename?: string, maxSize?: number|null, type?: string, enabled?: boolean}} options
944962
* @param {OptionsCallback<webpack.RuleSetRule>} ruleCallback
945963
*/
946964
configureFontRule(options = {}, ruleCallback = () => {}) {

0 commit comments

Comments
 (0)