How to use memory-fs - 10 common examples

To help you get started, we’ve selected a few memory-fs 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 zephraph / vue-graphql-loader / test / compiler.ts View on Github external
const webpackCompilation = (
  componentName: string,
  options: GraphQLLoaderOptions = defaultLoaderOptions
): Promise => {
  const vfs = new Memoryfs();
  const fixture = `./__fixtures__/${componentName}.vue`;
  const compiler = webpack({
    // @ts-ignore
    mode: 'production',
    // @ts-ignore
    context: __dirname,
    optimization: {
      minimize: false
    },
    entry: `./${fixture}`,
    output: {
      libraryTarget: 'commonjs',
      library: 'component',
      path: path.resolve(__dirname),
      filename: `${componentName}.js`
    },
github SinaMFE / assemblyscript-typescript-loader / test / helpers / compiler.js View on Github external
config = {
    devtool: config.devtool || 'sourcemap',
    context: path.resolve(__dirname, '..', 'fixtures'),
    entry: `./${fixture}`,
    output: output(config),
    module: module(config),
    plugins: plugins(config),
  };
  // Compiler Options
  options = Object.assign({ output: false }, options);

  if (options.output) del.sync(config.output.path);

  const compiler = webpack(config);

  if (!options.output) compiler.outputFileSystem = new MemoryFS();

  return new Promise((resolve, reject) => compiler.run((err, stats) => {
    if (err) reject(err);

    resolve(stats);
  }));
}
github GoogleChromeLabs / prerender-loader / src / index.js View on Github external
const entry = customEntry ? ('./' + customEntry) : convertPathToRelative(context, parentCompiler.options.entry, './');

  const outputOptions = {
    // fix: some plugins ignore/bypass outputfilesystem, so use a temp directory and ignore any writes.
    path: os.tmpdir(),
    filename: FILENAME
  };

  // Only copy over allowed plugins (excluding them breaks extraction entirely).
  const allowedPlugins = /(MiniCssExtractPlugin|ExtractTextPlugin)/i;
  const plugins = (parentCompiler.options.plugins || []).filter(c => allowedPlugins.test(c.constructor.name));

  // Compile to an in-memory filesystem since we just want the resulting bundled code as a string
  const compiler = parentCompilation.createChildCompiler('prerender', outputOptions, plugins);
  compiler.context = parentCompiler.context;
  compiler.outputFileSystem = new MemoryFs();

  // Define PRERENDER to be true within the SSR bundle
  new DefinePlugin({
    PRERENDER: 'true'
  }).apply(compiler);

  // ... then define PRERENDER to be false within the client bundle
  new DefinePlugin({
    PRERENDER: 'false'
  }).apply(parentCompiler);

  // Compile to CommonJS to be executed by Node
  new NodeTemplatePlugin(outputOptions).apply(compiler);
  new NodeTargetPlugin().apply(compiler);

  new LibraryTemplatePlugin('PRERENDER_RESULT', 'var').apply(compiler);
github Mayank1791989 / gql / src / __mocks__ / fs.js View on Github external
function createNewMemoryFileSystem(): MemoryFileSystem {
  const _fs = new MemoryFileSystem();
  // Note: binding all methods of _fs
  // some libs use individual fs method
  // e.g const writeFileSync = fs.writeFileSync
  //  writeFileSync() // this will call method with wrong this
  // happening in find-config package
  Object.keys(MemoryFileSystem.prototype).forEach((key) => {
    if (typeof _fs[key] === 'function') {
      _fs[key] = _fs[key].bind(_fs);
    }
  });
  return _fs;
}
github superawesomelabs / leo / packages / graphql-directory-api / src / gen-database / index.js View on Github external
// use root directory as output if we're using memoryFS
  let distFolder = memoryFS ? '/' : resolve(process.cwd(), outputDir);
  debug('distFolder', distFolder);
  debug('files', files);
  debug('dirs', process.cwd(), __dirname);
  const createdConfig = enablePlugins(plugins, pluginOpts, config({
    filepaths: files,
    plugins
  }, {
    outputPath: distFolder
  }));

  const compiler = webpack(createdConfig.resolve());
  if(memoryFS) {
    fs = new MemoryFS();
    compiler.outputFileSystem = fs;
  } else {
    mkdirp.sync(distFolder);
  }

  function webpackHandler(err, stats) {
    // Start Error Checking
    if (err) {
      // hard failure
      debug('webpack failed', err);
      callback(err);
      return;
    }
    const jsonStats = stats.toJson();
    if (jsonStats.errors.length > 0) {
      //soft failure
github Mayank1791989 / gql / src / __mocks__ / fs.js View on Github external
function createNewMemoryFileSystem(): MemoryFileSystem {
  const _fs = new MemoryFileSystem();
  // Note: binding all methods of _fs
  // some libs use individual fs method
  // e.g const writeFileSync = fs.writeFileSync
  //  writeFileSync() // this will call method with wrong this
  // happening in find-config package
  Object.keys(MemoryFileSystem.prototype).forEach((key) => {
    if (typeof _fs[key] === 'function') {
      _fs[key] = _fs[key].bind(_fs);
    }
  });
  return _fs;
}
github electron-userland / electron-webpack / test / src / helpers / helper.ts View on Github external
export async function testWebpack(configuration: Configuration, projectDir: string, checkCompilation = true) {
  if (Array.isArray(configuration)) {
    configuration.forEach(addCustomResolver)
  }
  else {
    addCustomResolver(configuration)
  }

  const fs = new MemoryFS()
  const stats = await new Promise((resolve, reject) => {
    compile(fs, configuration, resolve, reject)
  })

  if (checkCompilation) {
    expect(statToMatchObject(stats, projectDir, fs)).toMatchSnapshot()
    expect(bufferToString(fs.meta(projectDir), projectDir)).toMatchSnapshot()
  }
  return fs
}
github lttb / reshadow / packages / webpack / spec / compiler.js View on Github external
},
                    ],
                },
            ],
        },
        resolve: {
            modules: ['node_modules', path.resolve(__dirname, '../../')],
        },
        optimization: {
            splitChunks: {
                chunks: 'all',
            },
        },
    });

    compiler.outputFileSystem = new MemoryFS();

    return new Promise((resolve, reject) => {
        compiler.run((error, stats) => {
            if (error) {
                reject(new Error(error));
            }

            resolve({stats, compiler});
        });
    });
};
github Fitbit / webpack-cluster / src / CompilerUtil.js View on Github external
export function createCompiler(config, options) {
    const compiler = webpack(config);

    if (options.dryRun === true) {
        compiler.outputFileSystem = new MemoryFs();
    }

    return compiler;
}
github saltyshiomix / react-ssr / packages / static / src / optimize / development.ts View on Github external
import express from 'express';
import proxy from 'http-proxy-middleware';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import { configureWebpack } from './webpack.config';
import { getEntry } from './helpers';
import {
  getPageId,
  staticConfig,
  sleep,
} from '../helpers';

const cwd = process.cwd();

const ufs = require('unionfs').ufs;
const memfs = new MemoryFileSystem();
ufs.use(fs).use(memfs);

export default async (app: express.Application): Promise => {
  fse.removeSync(path.join(cwd, staticConfig.distDir));

  let compiled = false;
  const [entry, entryPages] = await getEntry(memfs);
  const webpackConfig: webpack.Configuration = configureWebpack(entry);
  const compiler: webpack.Compiler = webpack(webpackConfig);
  compiler.hooks.afterCompile.tap('finish', () => { compiled = true });
  compiler.inputFileSystem = ufs;

  const devServerPort = 8888;
  const devServer = new WebpackDevServer(compiler, {
    hot: true,
    noInfo: true,

memory-fs

A simple in-memory filesystem. Holds data in a javascript object.

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis

Popular memory-fs functions