Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.pending = true;
this.error = null;
logger.clear();
logger.progress('Building...');
try {
// Start worker farm, watcher, etc. if needed
await this.start();
// Emit start event, after bundler is initialised
this.emit('buildStart', this.entryFiles);
// If this is the initial bundle, ensure the output directory exists, and resolve the main asset.
if (isInitialBundle) {
await fs.mkdirp(this.options.outDir);
this.entryAssets = new Set();
for (let entry of this.entryFiles) {
let asset = await this.resolveAsset(entry);
this.buildQueue.add(asset);
this.entryAssets.add(asset);
}
}
// Build the queued assets.
let loadedAssets = await this.buildQueue.run();
// The changed assets are any that don't have a parent bundle yet
// plus the ones that were in the build queue.
let changedAssets = [...this.findOrphanAssets(), ...loadedAssets];
this.pending = true;
this.error = null;
logger.clear();
logger.progress('Building...');
try {
// Start worker farm, watcher, etc. if needed
await this.start();
// Emit start event, after bundler is initialised
this.emit('buildStart', this.entryFiles);
// If this is the initial bundle, ensure the output directory exists, and resolve the main asset.
if (isInitialBundle) {
await fs.mkdirp(this.options.outDir);
this.entryAssets = new Set();
for (let entry of this.entryFiles) {
try {
let asset = await this.resolveAsset(entry);
this.buildQueue.add(asset);
this.entryAssets.add(asset);
} catch (err) {
throw new Error(
`Cannot resolve entry "${entry}" from "${this.options.rootDir}"`,
);
}
}
if (this.entryAssets.size === 0) {
throw new Error('No entries found.');
async ensureDirExists() {
if (this.dirExists) {
return;
}
await fs.mkdirp(this.dir);
// Create sub-directories for every possible hex value
// This speeds up large caches on many file systems since there are fewer files in a single directory.
for (let i = 0; i < 256; i++) {
await fs.mkdirp(path.join(this.dir, ('00' + i.toString(16)).slice(-2)));
}
this.dirExists = true;
}
async ensureDirExists() {
if (this.dirExists) {
return;
}
await fs.mkdirp(this.dir);
// Create sub-directories for every possible hex value
// This speeds up large caches on many file systems since there are fewer files in a single directory.
for (let i = 0; i < 256; i++) {
await fs.mkdirp(path.join(this.dir, ('00' + i.toString(16)).slice(-2)));
}
this.dirExists = true;
}
async ensureDirExists() {
if (this.dirExists) {
return;
}
await fs.mkdirp(this.dir);
// Create sub-directories for every possible hex value
// This speeds up large caches on many file systems since there are fewer files in a single directory.
for (let i = 0; i < 256; i++) {
await fs.mkdirp(path.join(this.dir, ('00' + i.toString(16)).slice(-2)));
}
this.dirExists = true;
}
async rustcBuild() {
// Get output filename
await fs.mkdirp(this.options.cacheDir);
let name = md5(this.name);
this.wasmPath = path.join(this.options.cacheDir, name + '.wasm');
// Run rustc to compile the code
const args = [
'+nightly',
'--target',
RUST_TARGET,
'-O',
'--crate-type=cdylib',
this.name,
'-o',
this.wasmPath,
];
await exec('rustc', args);
async addAsset(asset) {
let contents = asset.generated[this.bundle.type];
if (!contents || (contents && contents.path)) {
contents = await fs.readFile(contents ? contents.path : asset.name);
}
// Create sub-directories if needed
if (this.bundle.name.includes(path.sep)) {
await fs.mkdirp(path.dirname(this.bundle.name));
}
this.size = contents.length;
await fs.writeFile(this.bundle.name, contents);
}