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

Commit

Permalink
feat: get options from this.options
Browse files Browse the repository at this point in the history
  • Loading branch information
s-panferov committed Feb 5, 2017
1 parent f24a81a commit f43a215
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';

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

Expand Down Expand Up @@ -35,11 +35,15 @@ function compiler(loader: Loader, text: string): void {
loader.cacheable();
}

const options = <QueryOptions>loaderUtils.parseQuery(loader.query);
const instanceName = options.instance || 'at-loader';
const instance = ensureInstance(loader, options, instanceName);
const rootCompiler = getRootCompiler(loader._compiler);

const query = <QueryOptions>loaderUtils.parseQuery(loader.query);
const options = (loader.options && loader.options.ts) || {};
const instanceName = query.instance || 'at-loader';
const instance = ensureInstance(loader, query, options, instanceName, rootCompiler);
const callback = loader.async();
const fileName = helpers.toUnix(loader.resourcePath);

let fileName = helpers.toUnix(loader.resourcePath);

instance.compiledFiles[fileName] = true;

Expand Down
30 changes: 18 additions & 12 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ export interface Loader {
clearDependencies: () => void;
emitFile: (fileName: string, text: string) => void;
options: {
atl?: {
}
ts?: LoaderConfig
};
}

export type QueryOptions = LoaderConfig & ts.CompilerOptions;

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

let id = 0;
export function ensureInstance(webpack: Loader, query: QueryOptions, instanceName: string): Instance {
const rootCompiler = getRootCompiler(webpack._compiler);
const watching = isWatching(rootCompiler);

let exInstance = resolveInstance(webpack._compiler, instanceName);
export function ensureInstance(
webpack: Loader,
query: QueryOptions,
options: LoaderConfig,
instanceName: string,
rootCompiler: any
): Instance {
let exInstance = resolveInstance(rootCompiler, instanceName);
if (exInstance) {
return exInstance;
}

const watching = isWatching(rootCompiler);

const context = rootCompiler.context;
let compilerInfo = setupTs(query.compiler);
let { tsImpl } = compilerInfo;

let { configFilePath, compilerConfig, loaderConfig } = readConfigFile(context, query, tsImpl);
let { configFilePath, compilerConfig, loaderConfig } = readConfigFile(context, query, options, tsImpl);

applyDefaults(
configFilePath,
Expand Down Expand Up @@ -264,6 +268,7 @@ function absolutize(fileName: string, context: string) {
export function readConfigFile(
context: string,
query: QueryOptions,
options: LoaderConfig,
tsImpl: typeof ts
): Configs {
let configFilePath: string;
Expand All @@ -290,7 +295,6 @@ export function readConfigFile(
}

let jsonConfigFile = tsImpl.readConfigFile(configFilePath, tsImpl.sys.readFile);

let compilerConfig = tsImpl.parseJsonConfigFileContent(
jsonConfigFile.config,
tsImpl.sys,
Expand All @@ -302,9 +306,11 @@ export function readConfigFile(
return {
configFilePath,
compilerConfig,
loaderConfig: _.defaults<LoaderConfig, LoaderConfig>(
loaderConfig: _.defaults(
query,
jsonConfigFile.config.awesomeTypescriptLoaderOptions)
jsonConfigFile.config.awesomeTypescriptLoaderOptions,
options
)
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/paths-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class PathsPlugin implements ResolverPlugin {

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

let { configFilePath, compilerConfig } = readConfigFile(process.cwd(), config, this.ts);
let { configFilePath, compilerConfig } = readConfigFile(process.cwd(), config, {}, this.ts);
this.options = compilerConfig.options;
this.configFilePath = configFilePath;

Expand Down

0 comments on commit f43a215

Please sign in to comment.