Skip to content

Commit ee5b227

Browse files
Harrison IfeanyichukwuHarrison Ifeanyichukwu
Harrison Ifeanyichukwu
authored and
Harrison Ifeanyichukwu
committed
fix: utilize typings output directory when copying typings
1 parent 01bc33c commit ee5b227

File tree

6 files changed

+48
-14
lines changed

6 files changed

+48
-14
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ You can override these options by creating and placing a `.buildrc.js` file in y
436436

437437
- **externals**: Defines list of external modules. By default, `peerDependency` modules are read from your project's package.json file and included automatically when generating lib builds. So you don't need to add those.
438438

439+
- **typingsDir**: Defines output folder to copy typings file over to. defaults to each build type `{outDir}/typings`
440+
439441
## Contributing
440442

441443
We welcome your own contributions, ranging from code refactoring, documentation improvements, new feature implementations, bugs/issues reporting, etc. **Thanks in advance!!!**

src/.buildrc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const config: Config = {
5656

5757
externals: [],
5858

59+
typingsDir: '',
60+
5961
/**
6062
* defines config settings for generating distributed codes. such as browser iife outputs
6163
*/

src/@types/index.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export declare interface CommonConfig {
5151
* list of external modules for the specific build, by default, peer dependencie modules are auto included as externals for lib builds
5252
*/
5353
externals?: string[];
54+
55+
/**
56+
* typings directory, defaults to .typings folder inside your output directory
57+
*/
58+
typingsDir?: string;
5459
}
5560

5661
export declare interface LibConfig extends CommonConfig {
@@ -136,6 +141,11 @@ export declare interface Config {
136141
*/
137142
externals: string[];
138143

144+
/**
145+
* typings folder
146+
*/
147+
typingsDir: string;
148+
139149
/**
140150
* defines config settings for generating distributed codes
141151
*/
@@ -230,6 +240,11 @@ export declare interface UserConfig {
230240
*/
231241
externals?: string[];
232242

243+
/**
244+
* typings directory, defaults to .typings folder inside your output directory
245+
*/
246+
typingsDir?: string;
247+
233248
/**
234249
* defines config settings for generating distributed codes.
235250
*/

src/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const COMMON_CONFIGS: (keyof CommonConfig)[] = [
88
'uglify',
99
'interop',
1010
'externals',
11+
'typingsDir',
1112
];
1213

1314
export const REGEX_FIELDS: (keyof CommonConfig)[] = ['assets', 'include', 'exclude'];

src/index.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import Bundler from './modules/Bundler';
2-
import { UserConfig } from './@types';
2+
import { UserConfig, Build } from './@types';
33

44
export default {
5-
/**
6-
* returns array of rollup build objects
7-
*
8-
* @param uglifierPlugin the uglifier plugin if uglify is enabled or null if not
9-
* @param otherPlugins array of other registered plugins
10-
* @param config string pointing to your project config file or config object. defaults to .buildrc.js
11-
*/
12-
getExports(uglifierPlugin: object | null, otherPlugins: object[], config: string | UserConfig = '.buildrc.js') {
13-
const bundler = new Bundler(uglifierPlugin, otherPlugins, config);
14-
return bundler.process();
15-
}
16-
};
5+
/**
6+
* returns array of rollup build objects
7+
*
8+
* @param uglifierPlugin the uglifier plugin if uglify is enabled or null if not
9+
* @param otherPlugins array of other registered plugins
10+
* @param config string pointing to your project config file or config object. defaults to .buildrc.js
11+
*/
12+
getExports(
13+
uglifierPlugin: object | null,
14+
otherPlugins: object[],
15+
config: string | UserConfig = '.buildrc.js'
16+
): Build[] {
17+
const bundler = new Bundler(uglifierPlugin, otherPlugins, config);
18+
return bundler.process();
19+
},
20+
};

src/modules/Bundler.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ export default class Bundler {
100100
this.mergeConfig(prop, resolvedConfig, resolvedConfig.distConfig);
101101
});
102102

103+
//resolve typings folder
104+
if (resolvedConfig.libConfig.typingsDir === '') {
105+
resolvedConfig.libConfig.typingsDir = path.join(resolvedConfig.libConfig.outDir, 'typings');
106+
}
107+
if (resolvedConfig.distConfig.typingsDir === '') {
108+
resolvedConfig.distConfig.typingsDir = path.join(resolvedConfig.distConfig.outDir, 'typings');
109+
}
110+
103111
//for lib config, add all per dependencies as externals
104112
if (packageFile.peerDependencies) {
105113
Object.keys(packageFile.peerDependencies).forEach(key => resolvedConfig.libConfig.externals.push(key));
@@ -134,7 +142,9 @@ export default class Bundler {
134142
src = oldRelativePath;
135143
const isTypeDefinitionFile = ext === '.d.ts';
136144

137-
if ((isTypeDefinitionFile && config.copyTypings) || (!isBuildFile && config.assets.some(regexMatches))) {
145+
if (isTypeDefinitionFile && config.copyTypings) {
146+
this.copyFile(filePath, path.join(config.typingsDir, oldRelativePath));
147+
} else if (!isTypeDefinitionFile && !isBuildFile && config.assets.some(regexMatches)) {
138148
this.copyFile(filePath, path.join(config.outDir, oldRelativePath));
139149
} else if (
140150
isBuildFile &&

0 commit comments

Comments
 (0)