Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit f43a215

Browse files
committed
feat: get options from this.options
1 parent f24a81a commit f43a215

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33

44
import { findCompiledModule, cache } from './cache';
55
import * as helpers from './helpers';
6-
import { QueryOptions, Loader, ensureInstance, Instance } from './instance';
6+
import { QueryOptions, Loader, ensureInstance, Instance, getRootCompiler } from './instance';
77
import { PathsPlugin } from './paths-plugin';
88
import { CheckerPlugin as _CheckerPlugin } from './watch-mode';
99

@@ -35,11 +35,15 @@ function compiler(loader: Loader, text: string): void {
3535
loader.cacheable();
3636
}
3737

38-
const options = <QueryOptions>loaderUtils.parseQuery(loader.query);
39-
const instanceName = options.instance || 'at-loader';
40-
const instance = ensureInstance(loader, options, instanceName);
38+
const rootCompiler = getRootCompiler(loader._compiler);
39+
40+
const query = <QueryOptions>loaderUtils.parseQuery(loader.query);
41+
const options = (loader.options && loader.options.ts) || {};
42+
const instanceName = query.instance || 'at-loader';
43+
const instance = ensureInstance(loader, query, options, instanceName, rootCompiler);
4144
const callback = loader.async();
42-
const fileName = helpers.toUnix(loader.resourcePath);
45+
46+
let fileName = helpers.toUnix(loader.resourcePath);
4347

4448
instance.compiledFiles[fileName] = true;
4549

src/instance.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ export interface Loader {
4242
clearDependencies: () => void;
4343
emitFile: (fileName: string, text: string) => void;
4444
options: {
45-
atl?: {
46-
}
45+
ts?: LoaderConfig
4746
};
4847
}
4948

5049
export type QueryOptions = LoaderConfig & ts.CompilerOptions;
5150

52-
function getRootCompiler(compiler) {
51+
export function getRootCompiler(compiler) {
5352
if (compiler.parentCompilation) {
5453
return getRootCompiler(compiler.parentCompilation.compiler);
5554
} else {
@@ -73,20 +72,25 @@ const BABEL_ERROR = colors.red(`\n\nBabel compiler cannot be found, please add i
7372
`);
7473

7574
let id = 0;
76-
export function ensureInstance(webpack: Loader, query: QueryOptions, instanceName: string): Instance {
77-
const rootCompiler = getRootCompiler(webpack._compiler);
78-
const watching = isWatching(rootCompiler);
79-
80-
let exInstance = resolveInstance(webpack._compiler, instanceName);
75+
export function ensureInstance(
76+
webpack: Loader,
77+
query: QueryOptions,
78+
options: LoaderConfig,
79+
instanceName: string,
80+
rootCompiler: any
81+
): Instance {
82+
let exInstance = resolveInstance(rootCompiler, instanceName);
8183
if (exInstance) {
8284
return exInstance;
8385
}
8486

87+
const watching = isWatching(rootCompiler);
88+
8589
const context = rootCompiler.context;
8690
let compilerInfo = setupTs(query.compiler);
8791
let { tsImpl } = compilerInfo;
8892

89-
let { configFilePath, compilerConfig, loaderConfig } = readConfigFile(context, query, tsImpl);
93+
let { configFilePath, compilerConfig, loaderConfig } = readConfigFile(context, query, options, tsImpl);
9094

9195
applyDefaults(
9296
configFilePath,
@@ -264,6 +268,7 @@ function absolutize(fileName: string, context: string) {
264268
export function readConfigFile(
265269
context: string,
266270
query: QueryOptions,
271+
options: LoaderConfig,
267272
tsImpl: typeof ts
268273
): Configs {
269274
let configFilePath: string;
@@ -290,7 +295,6 @@ export function readConfigFile(
290295
}
291296

292297
let jsonConfigFile = tsImpl.readConfigFile(configFilePath, tsImpl.sys.readFile);
293-
294298
let compilerConfig = tsImpl.parseJsonConfigFileContent(
295299
jsonConfigFile.config,
296300
tsImpl.sys,
@@ -302,9 +306,11 @@ export function readConfigFile(
302306
return {
303307
configFilePath,
304308
compilerConfig,
305-
loaderConfig: _.defaults<LoaderConfig, LoaderConfig>(
309+
loaderConfig: _.defaults(
306310
query,
307-
jsonConfigFile.config.awesomeTypescriptLoaderOptions)
311+
jsonConfigFile.config.awesomeTypescriptLoaderOptions,
312+
options
313+
)
308314
};
309315
}
310316

src/paths-plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PathsPlugin implements ResolverPlugin {
6767

6868
this.ts = setupTs(config.compiler).tsImpl;
6969

70-
let { configFilePath, compilerConfig } = readConfigFile(process.cwd(), config, this.ts);
70+
let { configFilePath, compilerConfig } = readConfigFile(process.cwd(), config, {}, this.ts);
7171
this.options = compilerConfig.options;
7272
this.configFilePath = configFilePath;
7373

0 commit comments

Comments
 (0)