Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.skip();
} else if (nodeVersion.major < minVersion.major) {
this.skip();
}
}
this.timeout(0);
var expected;
process.chdir(path.join(__dirname, fixtureDir));
shell.exec('npm install', { silent: true });
// TODO: log failures
rechoir.prepare(extensions, fixture);
switch (extension) {
case '.ts':
case '.tsx':
case '.esm.js':
expected = {
default: {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
},
},
};
}
// load any modules which were requested to be required
if (preload.length) {
// unique results first
preload.filter(function (value, index, self) {
return self.indexOf(value) === index;
}).forEach(function (dep) {
this.requireLocal(dep, findCwd(opts));
}, this);
}
// use rechoir to autoload any required modules
var autoloads;
if (configPath) {
autoloads = rechoir.prepare(this.extensions, configPath, cwd, true);
if (autoloads instanceof Error) {
autoloads = autoloads.failures;
}
if (Array.isArray(autoloads)) {
autoloads.forEach(function (attempt) {
if (attempt.error) {
this.emit('requireFail', attempt.moduleName, attempt.error);
} else {
this.emit('require', attempt.moduleName, attempt.module);
}
}, this);
}
}
return {
cwd: cwd,
}
// load any modules which were requested to be required
if (preload.length) {
// unique results first
preload.filter(function (value, index, self) {
return self.indexOf(value) === index;
}).forEach(function (dep) {
this.requireLocal(dep, findCwd(opts));
}, this);
}
// use rechoir to autoload any required modules
var autoloads;
if (configPath) {
autoloads = rechoir.prepare(this.extensions, configPath, cwd, true);
if (autoloads instanceof Error) {
autoloads = autoloads.failures;
}
if (Array.isArray(autoloads)) {
autoloads.forEach(function (attempt) {
if (attempt.error) {
this.emit('requireFail', attempt.moduleName, attempt.error);
} else {
this.emit('require', attempt.moduleName, attempt.module);
}
}, this);
}
}
return {
cwd: cwd,
module.exports = function(eventEmitter, extensions, configPath, cwd) {
extensions = extensions || {};
if (typeof configPath !== 'string') {
return;
}
var autoloads = rechoir.prepare(extensions, configPath, cwd, true);
if (autoloads instanceof Error) { // Only errors
autoloads.failures.forEach(function(failed) {
eventEmitter.emit('loader:failure', failed.moduleName, failed.error);
});
return;
}
if (!Array.isArray(autoloads)) { // Already required or no config.
return;
}
var succeeded = autoloads[autoloads.length - 1];
eventEmitter.emit('loader:success', succeeded.moduleName, succeeded.module);
};
export const webpackConfig = (cwd: string, configPath?: string) => {
const resolvedConfigPath = (() => {
if (!configPath) {
return defaultWebpackConfigPath(cwd);
}
if (path.isAbsolute(configPath)) {
return path.resolve(configPath);
}
return path.resolve(cwd, configPath);
})();
// register module loaders
rechoir.prepare(interpret.extensions, resolvedConfigPath);
const config: {
default: webpack.Configuration;
// eslint-disable-next-line global-require, import/no-dynamic-require
} = require(resolvedConfigPath);
return config.default || config;
};
function register (name) {
if (handlers.has(name)) {
return handlers.get(name)
}
const handlerPath = resolve(name, {basedir: pwd, extensions: ['.js', '.ts']})
try {
rechoir.prepare(extensions, handlerPath)
} catch (e) {
// pass, but log the error
log.error(`Error preparing transform for ${name}\n ${e.message}`)
}
const handler = _require(handlerPath)
handlers.set(name, handler.default || handler)
paths.set(name, handlerPath)
// only perform package version checks for installable mocks
if (handlerPath.includes('node_modules')) {
let pkgPath
let lpkg
try {
'use strict';
var path = require('path');
var config = require('interpret').extensions;
var rechoir = require('rechoir');
require('coffee-script/register');
rechoir.prepare(config, './fixture.coffee');
var filename = path.join(__dirname, 'fixture.coffee');
var coffee = require(filename);
if (typeof coffee.root === 'function') {
console.log('ok');
}
module.exports = function(eventEmitter, extensions, configPath, cwd) {
extensions = extensions || {};
if (!isString(configPath)) {
return;
}
var autoloads = rechoir.prepare(extensions, configPath, cwd, true);
if (autoloads instanceof Error) {
autoloads = autoloads.failures;
}
if (Array.isArray(autoloads)) {
autoloads.forEach(function (attempt) {
if (attempt.error) {
eventEmitter.emit('requireFail', attempt.moduleName, attempt.error);
} else {
eventEmitter.emit('require', attempt.moduleName, attempt.module);
}
});
}
};
const requireLoader = (extension) => {
try {
rechoir.prepare(fileTypes, `config${extension}`, cwd);
} catch (e) {
let message;
if (/no module loader/i.test(e.message)) {
const [, fileType] = e.message.match(/(".+").$/);
message = `A loader could not be found for the ${fileType} file type`;
} else {
const modules = e.failures.map(({ moduleName }) => `\n ${moduleName}`);
message = `${e.message.slice(0, -1)}:${modules}`;
}
const error = new RangeError(message);
error.code = 'ERR_MODULE_LOADER';
throw error;
}
};
const requireLoader = (extension) => {
try {
rechoir.prepare(fileTypes, `config${extension}`, cwd);
} catch (e) {
let message;
if (/no module loader/i.test(e.message)) {
const [, fileType] = e.message.match(/(".+").$/);
message = `A loader could not be found for the ${fileType} file type`;
} else {
const modules = e.failures.map(({ moduleName }) => `\n ${moduleName}`);
message = `${e.message.slice(0, -1)}:${modules}`;
}
const error = new RangeError(message);
error.code = 'ERR_MODULE_LOADER';
throw error;
}
};