Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new PostHTML().walk.call(program, (node: PostHTMLNode) => {
let parcelKey = md5FromString(`${asset.id}:${key++}`);
if (node.tag === 'script' || node.tag === 'style') {
let value = node.content && node.content.join('').trim();
if (value != null) {
let type;
if (node.tag === 'style') {
if (node.attrs && node.attrs.type) {
type = node.attrs.type.split('/')[1];
} else {
type = 'css';
}
} else if (node.attrs && node.attrs.type) {
// Skip JSON
if (SCRIPT_TYPES[node.attrs.type] === false) {
return node;
}
lookupAlias(aliases, filename, dir) {
// First, try looking up the exact filename
let alias = aliases[filename];
if (alias == null) {
// Otherwise, try replacing glob keys
for (let key in aliases) {
let val = aliases[key];
if (typeof val === 'string' && isGlob(key)) {
let re = micromatch.makeRe(key, {capture: true});
if (re.test(filename)) {
alias = filename.replace(re, val);
break;
}
}
}
}
if (typeof alias === 'string') {
return this.resolveFilename(alias, dir);
} else if (alias === false) {
return false;
}
return null;
send(data: WorkerMessage) {
if (!this.processQueue) {
this.sendQueue.push(data);
return;
}
let result = this.child.send(serialize(data).toString('base64'), error => {
if (error && error instanceof Error) {
// Ignore this, the workerfarm handles child errors
return;
}
this.processQueue = true;
if (this.sendQueue.length > 0) {
let queueCopy = this.sendQueue.slice(0);
this.sendQueue = [];
queueCopy.forEach(entry => this.send(entry));
}
});
if (!result || /^win/.test(process.platform)) {
// Queue is handling too much messages throttle it
}
}
let parcel = new Parcel({
entries: [path.join(process.cwd(), 'index.js')],
cliOpts: opts
});
let environment = new Environment({
context: 'node',
engines: {
node: process.versions.node
}
});
syncPromise(parcel.init());
let isProcessing = false;
// As Parcel is pretty much fully asynchronous, create an async function and wrap it in a syncPromise later...
async function fileProcessor(code, filename) {
if (isProcessing) {
return code;
}
try {
isProcessing = true;
let result = await parcel.runTransform({
filePath: filename,
env: environment
});
let devDeps = [];
switch (configRequest.meta.actionType) {
case 'transformation':
devDeps = parcelConfig.getTransformerNames(filePath, pipeline);
break;
case 'validation':
devDeps = parcelConfig.getValidatorNames(filePath);
break;
case 'dependency':
devDeps = parcelConfig.getResolverNames();
break;
}
devDeps.forEach(devDep => publicConfig.addDevDependency(devDep));
publicConfig.setResultHash(md5FromString(JSON.stringify(devDeps)));
publicConfig.setWatchGlob('**/.parcelrc');
// TODO: if extended config comes from a package, yarn.lock change should invalidate config request
for (let extendedFile of extendedFiles) {
publicConfig.addIncludedFile(extendedFile);
}
return config;
}
let optimizers = this.config.getOptimizerNames(filePath);
let deps = Promise.all(
[packager, ...optimizers].map(async pkg => {
let {pkg: resolvedPkg} = await this.options.packageManager.resolve(
`${pkg}/package.json`,
`${this.config.filePath}/index`,
);
let version = nullthrows(resolvedPkg).version;
return [pkg, version];
}),
);
// TODO: add third party configs to the cache key
let {minify, scopeHoist, sourceMaps} = this.options;
return md5FromObject({
parcelVersion: PARCEL_VERSION,
deps,
opts: {minify, scopeHoist, sourceMaps},
hash: bundleGraph.getHash(bundle),
});
}
export function getEnvironmentHash(env: Environment) {
// context is excluded from hash so that assets can be shared between e.g. workers and browser.
// Different engines should be sufficient to distinguish multi-target builds.
return md5FromObject({
engines: env.engines,
includeNodeModules: env.includeNodeModules,
outputFormat: env.outputFormat,
isLibrary: env.isLibrary,
});
}
async getCacheKey(assetGraph: AssetGraph) {
let bundler = this.config.bundler;
let {pkg} = await this.options.packageManager.resolve(
`${bundler}/package.json`,
`${this.config.filePath}/index`, // TODO: is this right?
);
let version = nullthrows(pkg).version;
return md5FromObject({
parcelVersion: PARCEL_VERSION,
bundler,
version,
hash: assetGraph.getHash(),
});
}
const {promisify} = require('@parcel/utils');
const fs = require('fs');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
exports.readFile = promisify(fs.readFile);
exports.writeFile = promisify(fs.writeFile);
exports.stat = promisify(fs.stat);
exports.readdir = promisify(fs.readdir);
exports.unlink = promisify(fs.unlink);
exports.rimraf = promisify(rimraf);
exports.realpath = async function(path) {
const realpath = promisify(fs.realpath);
try {
path = await realpath(path);
} catch (e) {
// do nothing
}
return path;
};
exports.lstat = promisify(fs.lstat);
exports.exists = function(filename) {
return new Promise(resolve => {
fs.exists(filename, resolve);
exports.realpath = async function(path) {
const realpath = promisify(fs.realpath);
try {
path = await realpath(path);
} catch (e) {
// do nothing
}
return path;
};
exports.lstat = promisify(fs.lstat);