Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const randomName = `test-${new Date().getTime()}-${Math.random()}`;
const root = path.join(appRoot.path, ".fusebox/old-tests/", randomName);
const projectsHomeDir = path.join(root, "project");
const modulesFolder = path.join(root, "modules");
fsExtra.ensureDirSync(projectsHomeDir);
fsExtra.ensureDirSync(modulesFolder);
const serverOnly = opts.server === true;
const output: any = {
modules: {},
};
const scripts = [];
// creating modules
return each(opts.modules, (moduleParams, name) => {
return new Promise((resolve, reject) => {
moduleParams.homeDir = path.join(modulesFolder, name);
moduleParams.output = path.join(modulesFolder, name, "dist/index.js");
moduleParams.package = name;
moduleParams.ensureTsConfig = false;
moduleParams.cache = false;
moduleParams.log = false;
moduleParams.tsConfig = path.join(appRoot.path, "tests/_helpers/fixtures", "tsconfig.json");
createFiles(moduleParams.homeDir, moduleParams.files);
delete moduleParams.files;
const fuse = FuseBox.init(moduleParams);
fuse
.bundle("index.js")
.cache(false)
.instructions(moduleParams.instructions);
public static perform(core: QuantumCore, file: FileAbstraction): Promise {
return each(file.dynamicImportStatements, (statement: RequireStatement) => {
let target = statement.resolve();
// if we can resolve a dynamic statements
// that means that it could be technically mapped to a split bundle
// or just resolved as it is
if (target) {
//console.log(target);
target.canBeRemoved = false;
if (!target.dependents.has(file)) {
target.dependents.add(file);
}
const bit = new QuantumBit(target, statement);
statement.isDynamicImport = true;
target.quantumBitEntry = true;
target.quantumBit = bit;
private async processCSS() {
if (!this.opts.shouldGenerateCSS()) {
return;
}
await each(this.producerAbstraction.bundleAbstractions, (bundleAbstraction: BundleAbstraction) => {
return each(bundleAbstraction.packageAbstractions, (packageAbstraction: PackageAbstraction) => {
return each(packageAbstraction.fileAbstractions, (fileAbstraction: FileAbstraction) => {
// make sure that the files that were removed
// during treeshake aren't grouped and processed
if (!fileAbstraction.canBeRemoved) {
return CSSModifications.perform(this, fileAbstraction);
}
});
});
});
}
styleFile.sourceMap,
styleFile,
);
if (styleFile.cssDependencies) {
styleFile.cssDependencies.forEach(path => {
cache.styles[path] = 1;
});
}
return styleFile;
});
}
});
await each(styleFiles, styleFile => {
if (styleFile.alternativeContent) {
concat.add(null, styleFile.alternativeContent);
} else {
// TODO: Do we need this anymore? Everything seems to work without?
concat.add(
null,
`require('fuse-box-css')('${styleFile.info.fuseBoxPath}', ${JSON.stringify(styleFile.contents)})`,
styleFile.sourceMap,
);
}
});
}
if (file.context.useCache) {
const hasGlobal = file.context.isGlobalyIgnored("process");
const process = hasGlobal ? "global.process" : "process";
public static perform(core: QuantumCore, file: FileAbstraction): Promise {
if (core.opts.shouldReplaceProcessEnv()) {
return each(file.processNodeEnv, (env: ReplaceableBlock) => {
// working with conditional
// removing dead code here
if (env.isConditional) {
env.handleActiveCode();
} else {
env.replaceWithValue();
}
});
}
}
}
public static perform(core: QuantumCore, file: FileAbstraction) {
// FuseBox.isServer
return each(file.fuseboxIsEnvConditions, (replacable: ReplaceableBlock) => {
if (core.opts.isTargetUniveral()) {
if (replacable.identifier === "isServer") {
replacable.setFunctionName(`${core.opts.quantumVariableName}.cs`);
}
if (replacable.identifier === "isBrowser") {
replacable.setFunctionName(`${core.opts.quantumVariableName}.cb`);
}
} else {
if (replacable.isConditional) {
replacable.handleActiveCode();
} else {
replacable.replaceWithValue();
}
}
});
}
public transform(file): Promise {
// reduce? might it help here?
// each resolves promises in a waterfall
return each(this.plugins, (plugin) => {
if (utils.isFunction(plugin.initialize)) {
return plugin.initialize.apply(plugin, [file.context]);
}
if (utils.isFunction(plugin.transform)) {
return plugin.transform.apply(plugin, [file]);
}
});
}
const $printStats = (data, took) => {
if (cursor) {
const amount = data.length;
let totalTasks = 0;
let failed = 0;
let passed = 0;
realm_utils_1.each(data, items => {
realm_utils_1.each(items, (info, item) => {
totalTasks += info.tasks.length;
realm_utils_1.each(info.tasks, task => {
if (task.data.success) {
passed++;
}
if (task.data.error) {
failed++;
}
});
});
});
cursor.write("\n");
cursor.write(" ☞ ");
cursor.write("\n ");
cursor.green().write(` ${passed} passed `);
public exec() {
return each(this.activities, (activity: any) => activity && activity()).then(() => {
if (this.completedCallback) {
this.completedCallback(this.files);
}
this.files = [];
});
}
}
public generateAbstraction(opts?: ProducerAbtractionOptions): Promise {
const abstraction = new ProducerAbstraction(opts);
return each(this.bundles, (bundle: Bundle) => {
const bundleAbstraction = new BundleAbstraction(bundle.name);
abstraction.registerBundleAbstraction(bundleAbstraction);
return bundleAbstraction.parse(bundle.generatedCode.toString());
}).then(() => {
return abstraction;
});
}