Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function tryRequire(specifier: string) {
const resolved = resolve(specifier);
if (!resolved) {
return null;
}
let requiredModule = null;
try {
requiredModule = require(resolved);
} catch (e) {
// ignore
}
return requiredModule;
}
/* eslint-disable @typescript-eslint/indent */
import { resolve } from 'just-task';
import { tryRequire } from '../../tryRequire';
const styleLoader = resolve('@microsoft/loader-load-themed-styles') || resolve('style-loader');
const sassLoader = resolve('node-sass') && resolve('sass-loader');
const cssLoader = resolve('css-loader');
const postCssLoader = resolve('postcss-loader');
const cssTest = /\.css$/;
const cssModuleTest = /\.module\.css$/;
const sassTest = /\.(scss|sass)$/;
const sassModuleTest = /\.module\.(scss|sass)$/;
const defaultIdentName = '[name]_[local]_[hash:base64:5]';
interface CssLoaderOptions {
modules?: boolean;
localIdentName?: string;
}
function createStyleLoaderRule(cssOptions: CssLoaderOptions, preprocessor: 'sass-loader' | null = null): any {
const preloaders = [
...(postCssLoader
/* eslint-disable @typescript-eslint/indent */
import { resolve } from 'just-task';
import { tryRequire } from '../../tryRequire';
const styleLoader = resolve('@microsoft/loader-load-themed-styles') || resolve('style-loader');
const sassLoader = resolve('node-sass') && resolve('sass-loader');
const cssLoader = resolve('css-loader');
const postCssLoader = resolve('postcss-loader');
const cssTest = /\.css$/;
const cssModuleTest = /\.module\.css$/;
const sassTest = /\.(scss|sass)$/;
const sassModuleTest = /\.module\.(scss|sass)$/;
const defaultIdentName = '[name]_[local]_[hash:base64:5]';
interface CssLoaderOptions {
modules?: boolean;
localIdentName?: string;
}
function createStyleLoaderRule(cssOptions: CssLoaderOptions, preprocessor: 'sass-loader' | null = null): any {
const preloaders = [
...(postCssLoader
? [
export function tscTask(options: TscTaskOptions): TaskFunction {
const tsConfigFile = resolveCwd('./tsconfig.json');
const tscCmd = resolve('typescript/lib/tsc.js');
if (!tscCmd) {
throw new Error('cannot find tsc');
}
return function tsc() {
// Read from options argument, if not there try the tsConfigFile found in root, if not then skip and use no config
options.project = (options && options.project) || tsConfigFile || undefined;
if (options.project && fs.existsSync(options.project as string)) {
logger.info(`Running ${tscCmd} with ${options.project}`);
const args = Object.keys(options).reduce(
(args, option) => {
if (typeof options[option] === 'string') {
return args.concat(['--' + option, options[option] as string]);
/* eslint-disable @typescript-eslint/indent */
import { resolve } from 'just-task';
import { tryRequire } from '../../tryRequire';
const styleLoader = resolve('@microsoft/loader-load-themed-styles') || resolve('style-loader');
const sassLoader = resolve('node-sass') && resolve('sass-loader');
const cssLoader = resolve('css-loader');
const postCssLoader = resolve('postcss-loader');
const cssTest = /\.css$/;
const cssModuleTest = /\.module\.css$/;
const sassTest = /\.(scss|sass)$/;
const sassModuleTest = /\.module\.(scss|sass)$/;
const defaultIdentName = '[name]_[local]_[hash:base64:5]';
interface CssLoaderOptions {
modules?: boolean;
localIdentName?: string;
}
function createStyleLoaderRule(cssOptions: CssLoaderOptions, preprocessor: 'sass-loader' | null = null): any {
const preloaders = [
Object.keys(versionInfo).forEach(name => {
const spec = versionSpec[name];
const info = versionInfo[name];
let updateVersion: string | undefined;
if (semver.validRange(spec)) {
updateVersion = semver.maxSatisfying(info.versions, spec);
} else {
updateVersion = info.tags[spec] || info.tags.latest;
}
let packageJsonVersion = '';
const resolved = resolve(`${name}/package.json`);
if (resolved) {
packageJsonVersion = JSON.parse(fs.readFileSync(resolved).toString()).version;
}
if (updateVersion && updateVersion !== packageJsonVersion) {
keepUpdated[name] = updateVersion;
}
});
return function tslint() {
const tslintCmd = resolve('tslint/lib/tslintCli.js');
if (projectFile && tslintCmd && fs.existsSync(projectFile)) {
logger.info(`Running tslint`);
const args = [
'--project',
projectFile,
'-t',
'stylish',
'-r',
path.dirname(resolve('tslint-microsoft-contrib') || '')
];
if (options.fix) {
args.push('--fix');
}
return function tslint() {
const tslintCmd = resolve('tslint/lib/tslintCli.js');
if (projectFile && tslintCmd && fs.existsSync(projectFile)) {
logger.info(`Running tslint`);
const args = [
'--project',
projectFile,
'-t',
'stylish',
'-r',
path.dirname(resolve('tslint-microsoft-contrib') || '')
];
if (options.fix) {
args.push('--fix');
}
const cmd = encodeArgs([process.execPath, tslintCmd, ...args]).join(' ');
logger.info(cmd);
return exec(cmd, { stdout: process.stdout, stderr: process.stderr });
} else {
return Promise.resolve();
}
};
}
export function tscWatchTask(options: TscTaskOptions): TaskFunction {
const tsConfigFile = resolveCwd('./tsconfig.json');
const tscCmd = resolve('typescript/lib/tsc.js');
if (!tscCmd) {
throw new Error('cannot find tsc');
}
return function tscWatch() {
options.project = options.project || tsConfigFile || undefined;
if (options.project && fs.existsSync(options.project as string)) {
logger.info(`Running ${tscCmd} with ${options.project} in watch mode`);
const args = Object.keys(options).reduce(
(args, option) => {
if (typeof options[option] === 'string') {
return args.concat(['--' + option, options[option] as string]);
} else if (typeof options[option] === 'boolean') {