Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function bundler(
entries: FilePath | Array,
opts?: InitialParcelOptions,
) {
return new Parcel({
entries,
disableCache: true,
logLevel: 'none',
defaultConfig,
inputFS,
outputFS,
workerFarm,
packageManager: new NodePackageManager(inputFS),
defaultEngines: {
browsers: ['last 1 Chrome version'],
node: '8',
},
// $FlowFixMe
...opts,
});
}
initialOptions: InitialParcelOptions
): Promise {
let entries: Array;
if (initialOptions.entries == null || initialOptions.entries === '') {
entries = [];
} else if (Array.isArray(initialOptions.entries)) {
entries = initialOptions.entries.map(entry => path.resolve(entry));
} else {
entries = [path.resolve(initialOptions.entries)];
}
let inputFS = initialOptions.inputFS || new NodeFS();
let outputFS = initialOptions.outputFS || new NodeFS();
let packageManager =
initialOptions.packageManager || new NodePackageManager(inputFS);
let rootDir =
initialOptions.rootDir != null
? path.resolve(initialOptions.rootDir)
: getRootDir(entries);
let projectRootFile =
(await resolveConfig(inputFS, path.join(rootDir, 'index'), [
...LOCK_FILE_NAMES,
'.git',
'.hg'
])) || path.join(inputFS.cwd(), 'index'); // ? Should this just be rootDir
let lockFile = null;
let rootFileName = path.basename(projectRootFile);
if (LOCK_FILE_NAMES.includes(rootFileName)) {
import {NodePackageManager} from '@parcel/package-manager';
import {NodeFS} from '@parcel/fs';
// $FlowFixMe this is untyped
import defaultConfigContents from '@parcel/config-default';
// $FlowFixMe this is untyped
import Module from 'module';
import path from 'path';
// $FlowFixMe this is untyped
import {addHook} from 'pirates';
import Parcel, {INTERNAL_RESOLVE, INTERNAL_TRANSFORM} from '@parcel/core';
import syncPromise from './syncPromise';
let hooks = {};
let lastDisposable;
let packageManager = new NodePackageManager(new NodeFS());
let defaultConfig = {
...defaultConfigContents,
filePath: packageManager.resolveSync('@parcel/config-default', __filename)
.resolved,
};
function register(inputOpts?: InitialParcelOptions): IDisposable {
let opts: InitialParcelOptions = {
...defaultConfig,
...(inputOpts || {}),
};
// Replace old hook, as this one likely contains options.
if (lastDisposable) {
lastDisposable.dispose();
}
async function run(entries: Array, command: any) {
entries = entries.map(entry => path.resolve(entry));
if (entries.length === 0) {
console.log('No entries found');
return;
}
let Parcel = require('@parcel/core').default;
let packageManager = new NodePackageManager(new NodeFS());
let defaultConfig: ParcelConfigFile = await packageManager.require(
'@parcel/config-default',
__filename
);
let parcel = new Parcel({
entries,
packageManager,
defaultConfig: {
...defaultConfig,
filePath: (await packageManager.resolve(
'@parcel/config-default',
__filename
)).resolved
},
patchConsole: true,
...(await normalizeOptions(command))