How to use the just-task.resolve function in just-task

To help you get started, we’ve selected a few just-task examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / just / packages / just-scripts / src / tryRequire.ts View on Github external
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;
}
github microsoft / just / packages / just-scripts / src / webpack / overlays / stylesOverlay.ts View on Github external
/* 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
github microsoft / just / packages / just-scripts / src / webpack / overlays / stylesOverlay.ts View on Github external
/* 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
      ? [
github microsoft / just / packages / just-scripts / src / tasks / tscTask.ts View on Github external
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]);
github microsoft / just / packages / just-scripts / src / webpack / overlays / stylesOverlay.ts View on Github external
/* 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 = [
github microsoft / just / packages / just-task-preset / src / outdatedTask.ts View on Github external
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;
    }
  });
github microsoft / just / packages / just-scripts / src / tasks / tslintTask.ts View on Github external
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');
      }
github microsoft / just / packages / just-scripts / src / tasks / tslintTask.ts View on Github external
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();
    }
  };
}
github microsoft / just / packages / just-scripts / src / tasks / tscTask.ts View on Github external
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') {