diff --git a/packages/core/core/src/AssetGraph.js b/packages/core/core/src/AssetGraph.js index d8c69f5e6f1..fe72be1da0b 100644 --- a/packages/core/core/src/AssetGraph.js +++ b/packages/core/core/src/AssetGraph.js @@ -29,6 +29,7 @@ import nullthrows from 'nullthrows'; import {ContentGraph} from '@parcel/graph'; import {createDependency} from './Dependency'; import {type ProjectPath, fromProjectPathRelative} from './projectPath'; +import {DependencyFlags, EnvironmentFlags} from './types'; type InitOpts = {| entries?: Array, @@ -230,13 +231,14 @@ export default class AssetGraph extends ContentGraph { env: target.env, isEntry: true, needsStableName: true, - symbols: target.env.isLibrary - ? new Map([['*', {local: '*', isWeak: true, loc: null}]]) - : undefined, + symbols: + target.env.flags & EnvironmentFlags.IS_LIBRARY + ? new Map([['*', {local: '*', isWeak: true, loc: null}]]) + : undefined, }), ); - if (node.value.env.isLibrary) { + if (node.value.env.flags & EnvironmentFlags.IS_LIBRARY) { // in library mode, all of the entry's symbols are "used" node.usedSymbolsDown.add('*'); node.usedSymbolsUp.set('*', undefined); @@ -401,7 +403,10 @@ export default class AssetGraph extends ContentGraph { defer = deps.every( d => d.symbols && - !(d.env.isLibrary && d.isEntry) && + !( + d.env.flags & EnvironmentFlags.IS_LIBRARY && + d.flags & DependencyFlags.ENTRY + ) && !d.symbols.has('*') && ![...d.symbols.keys()].some(symbol => { if (!resolvedAsset.symbols) return true; diff --git a/packages/core/core/src/BundleGraph.js b/packages/core/core/src/BundleGraph.js index a4a9122056c..32f03f2a69d 100644 --- a/packages/core/core/src/BundleGraph.js +++ b/packages/core/core/src/BundleGraph.js @@ -37,7 +37,14 @@ import {ContentGraph, ALL_EDGE_TYPES, mapVisitor} from '@parcel/graph'; import {Hash, hashString} from '@parcel/rust'; import {DefaultMap, objectSortedEntriesDeep, getRootDir} from '@parcel/utils'; -import {Priority, BundleBehavior, SpecifierType} from './types'; +import { + Priority, + BundleBehavior, + SpecifierType, + AssetFlags, + EnvironmentFlags, + EnvironmentContextNames, +} from './types'; import {getBundleGroupId, getPublicId} from './utils'; import {ISOLATED_ENVS} from './public/Environment'; import {fromProjectPath, fromProjectPathRelative} from './projectPath'; @@ -201,7 +208,7 @@ export default class BundleGraph { if ( node.type === 'dependency' && node.value.symbols != null && - node.value.env.shouldScopeHoist && + node.value.env.flags & EnvironmentFlags.SHOULD_SCOPE_HOIST && // Disable in dev mode because this feature is at odds with safeToIncrementallyBundle isProduction ) { @@ -528,7 +535,7 @@ export default class BundleGraph { ? BundleBehavior[opts.bundleBehavior] : null, isSplittable: opts.entryAsset - ? opts.entryAsset.isBundleSplittable + ? Boolean(opts.entryAsset.flags & AssetFlags.IS_BUNDLE_SPLITTABLE) : opts.isSplittable, isPlaceholder, target, @@ -1301,7 +1308,7 @@ export default class BundleGraph { // If a bundle's environment is isolated, it can't access assets present // in any ancestor bundles. Don't consider any assets reachable. if ( - ISOLATED_ENVS.has(bundle.env.context) || + ISOLATED_ENVS.has(EnvironmentContextNames[bundle.env.context]) || !bundle.isSplittable || bundle.bundleBehavior === BundleBehavior.isolated || bundle.bundleBehavior === BundleBehavior.inline diff --git a/packages/core/core/src/CommittedAsset.js b/packages/core/core/src/CommittedAsset.js index 9bc94e3adf4..835e8e160ae 100644 --- a/packages/core/core/src/CommittedAsset.js +++ b/packages/core/core/src/CommittedAsset.js @@ -8,6 +8,7 @@ import SourceMap from '@parcel/source-map'; import {bufferStream, blobToStream, streamFromPromise} from '@parcel/utils'; import {generateFromAST} from './assetUtils'; import {deserializeRaw} from './serializer'; +import {AssetFlags} from './types'; export default class CommittedAsset { value: Asset; @@ -27,7 +28,7 @@ export default class CommittedAsset { getContent(): Blob | Promise { if (this.content == null) { if (this.value.contentKey != null) { - if (this.value.isLargeBlob) { + if (this.value.flags & AssetFlags.LARGE_BLOB) { return this.options.cache.getStream(this.value.contentKey); } else { return this.options.cache.getBlob(this.value.contentKey); diff --git a/packages/core/core/src/Dependency.js b/packages/core/core/src/Dependency.js index 588ccedda7d..e2882748d27 100644 --- a/packages/core/core/src/Dependency.js +++ b/packages/core/core/src/Dependency.js @@ -15,6 +15,7 @@ import { Priority, BundleBehavior, ExportsCondition, + DependencyFlags, } from './types'; import {toInternalSourceLocation} from './utils'; @@ -63,20 +64,34 @@ export function createDependency( (opts.packageConditions ? JSON.stringify(opts.packageConditions) : ''), ); + let { + placeholder, + promiseSymbol, + importAttributes, + isESM, + shouldWrap, + webworker, + ...meta + } = opts.meta ?? {}; + let dep: Dependency = { id, specifier: opts.specifier, specifierType: SpecifierType[opts.specifierType], priority: Priority[opts.priority ?? 'sync'], - needsStableName: opts.needsStableName ?? false, bundleBehavior: opts.bundleBehavior ? BundleBehavior[opts.bundleBehavior] - : null, - isEntry: opts.isEntry ?? false, - isOptional: opts.isOptional ?? false, + : 255, + flags: + (opts.needsStableName ? DependencyFlags.NEEDS_STABLE_NAME : 0) | + (opts.isEntry ? DependencyFlags.ENTRY : 0) | + (opts.isOptional ? DependencyFlags.OPTIONAL : 0) | + (isESM ? DependencyFlags.IS_ESM : 0) | + (shouldWrap ? DependencyFlags.SHOULD_WRAP : 0) | + (webworker ? DependencyFlags.IS_WEBWORKER : 0), loc: toInternalSourceLocation(projectRoot, opts.loc), env: opts.env, - meta: opts.meta || {}, + meta, target: opts.target, sourceAssetId: opts.sourceAssetId, sourcePath: toProjectPath(projectRoot, opts.sourcePath), @@ -98,6 +113,21 @@ export function createDependency( pipeline: opts.pipeline, }; + if (typeof placeholder === 'string') { + dep.placeholder = placeholder; + } + + if (typeof promiseSymbol === 'string') { + dep.promiseSymbol = promiseSymbol; + } + + if (importAttributes && typeof importAttributes === 'object') { + dep.importAttributes = Object.entries(importAttributes).map(([k, v]) => ({ + key: k, + value: (v: any), + })); + } + if (opts.packageConditions) { convertConditions(opts.packageConditions, dep); } @@ -106,7 +136,7 @@ export function createDependency( } export function mergeDependencies(a: Dependency, b: Dependency): void { - let {meta, symbols, needsStableName, isEntry, isOptional, ...other} = b; + let {meta, symbols, flags, ...other} = b; Object.assign(a, other); Object.assign(a.meta, meta); if (a.symbols && symbols) { @@ -114,9 +144,15 @@ export function mergeDependencies(a: Dependency, b: Dependency): void { a.symbols.set(k, v); } } - if (needsStableName) a.needsStableName = true; - if (isEntry) a.isEntry = true; - if (!isOptional) a.isOptional = false; + if (flags & DependencyFlags.NEEDS_STABLE_NAME) { + a.flags |= DependencyFlags.NEEDS_STABLE_NAME; + } + if (flags & DependencyFlags.ENTRY) { + a.flags |= DependencyFlags.ENTRY; + } + if (!(flags & DependencyFlags.OPTIONAL)) { + a.flags &= ~DependencyFlags.OPTIONAL; + } } function convertConditions(conditions: Array, dep: Dependency) { diff --git a/packages/core/core/src/Environment.js b/packages/core/core/src/Environment.js index 2c471350d60..617d9154c33 100644 --- a/packages/core/core/src/Environment.js +++ b/packages/core/core/src/Environment.js @@ -9,6 +9,15 @@ import {hashString} from '@parcel/rust'; import {toInternalSourceLocation} from './utils'; import PublicEnvironment from './public/Environment'; import {environmentToInternalEnvironment} from './public/Environment'; +import { + EnvironmentContext, + EnvironmentContextNames, + EnvironmentFlags, + OutputFormat, + OutputFormatNames, + SourceType, + SourceTypeNames, +} from './types'; const DEFAULT_ENGINES = { browsers: ['> 0.25%'], @@ -94,16 +103,19 @@ export function createEnvironment({ } } + let flags = + (isLibrary ? EnvironmentFlags.IS_LIBRARY : 0) | + (shouldOptimize ? EnvironmentFlags.SHOULD_OPTIMIZE : 0) | + (shouldScopeHoist ? EnvironmentFlags.SHOULD_SCOPE_HOIST : 0); + let res: Environment = { id: '', - context, + context: EnvironmentContext[context], engines, includeNodeModules, - outputFormat, - sourceType, - isLibrary, - shouldOptimize, - shouldScopeHoist, + outputFormat: OutputFormat[outputFormat], + sourceType: SourceType[sourceType], + flags, sourceMap, loc, }; @@ -129,6 +141,12 @@ export function mergeEnvironments( // $FlowFixMe - ignore the `id` that is already on a return createEnvironment({ ...a, + context: EnvironmentContextNames[a.context], + outputFormat: OutputFormatNames[a.outputFormat], + sourceType: SourceTypeNames[a.sourceType], + isLibrary: Boolean(a.flags & EnvironmentFlags.IS_LIBRARY), + shouldOptimize: Boolean(a.flags & EnvironmentFlags.SHOULD_OPTIMIZE), + shouldScopeHoist: Boolean(a.flags & EnvironmentFlags.SHOULD_SCOPE_HOIST), ...b, loc: b.loc ? toInternalSourceLocation(projectRoot, b.loc) : a.loc, }); @@ -142,9 +160,7 @@ function getEnvironmentHash(env: Environment): string { env.includeNodeModules, env.outputFormat, env.sourceType, - env.isLibrary, - env.shouldOptimize, - env.shouldScopeHoist, + env.flags, env.sourceMap, ]), ); diff --git a/packages/core/core/src/PackagerRunner.js b/packages/core/core/src/PackagerRunner.js index 7876f275c5e..ad67752a901 100644 --- a/packages/core/core/src/PackagerRunner.js +++ b/packages/core/core/src/PackagerRunner.js @@ -62,6 +62,7 @@ import {getInvalidationId, getInvalidationHash} from './assetUtils'; import {optionsProxy} from './utils'; import {invalidateDevDeps} from './requests/DevDepRequest'; import {tracer, PluginTracer} from '@parcel/profiler'; +import {EnvironmentContext} from './types'; type Opts = {| config: ParcelConfig, @@ -584,7 +585,7 @@ export default class PackagerRunner { sourceRoot = bundle.env.sourceMap.sourceRoot; } else if ( this.options.serveOptions && - bundle.target.env.context === 'browser' + bundle.target.env.context === EnvironmentContext.browser ) { sourceRoot = '/__parcel_source_root'; } @@ -594,7 +595,7 @@ export default class PackagerRunner { bundle.env.sourceMap.inlineSources !== undefined ) { inlineSources = bundle.env.sourceMap.inlineSources; - } else if (bundle.target.env.context !== 'node') { + } else if (bundle.target.env.context !== EnvironmentContext.node) { // inlining should only happen in production for browser targets by default inlineSources = this.options.mode === 'production'; } diff --git a/packages/core/core/src/SymbolPropagation.js b/packages/core/core/src/SymbolPropagation.js index 7bac77187dd..99e8c83f6fc 100644 --- a/packages/core/core/src/SymbolPropagation.js +++ b/packages/core/core/src/SymbolPropagation.js @@ -16,7 +16,7 @@ import nullthrows from 'nullthrows'; import {setEqual} from '@parcel/utils'; import logger from '@parcel/logger'; import {md, convertSourceLocationToHighlight} from '@parcel/diagnostic'; -import {BundleBehavior} from './types'; +import {AssetFlags, BundleBehavior} from './types'; import {fromProjectPathRelative, fromProjectPath} from './projectPath'; export function propagateSymbols({ @@ -150,7 +150,7 @@ export function propagateSymbols({ let depUsedSymbolsDown = new Set(); dep.usedSymbolsDown = depUsedSymbolsDown; if ( - assetNode.value.sideEffects || + assetNode.value.flags & AssetFlags.SIDE_EFFECTS || // Incoming dependency with cleared symbols addAll || // For entries, we still need to add dep.value.symbols of the entry (which are "used" but not according to the symbols data) @@ -408,7 +408,8 @@ export function propagateSymbols({ let reexport = reexportedSymbols.get(s); let v = // Forward a reexport only if the current asset is side-effect free and not external - !assetNode.value.sideEffects && reexport != null + !(assetNode.value.flags & AssetFlags.SIDE_EFFECTS) && + reexport != null ? reexport : { asset: assetNode.id, diff --git a/packages/core/core/src/Transformation.js b/packages/core/core/src/Transformation.js index ca25f703d85..54a5746d0b1 100644 --- a/packages/core/core/src/Transformation.js +++ b/packages/core/core/src/Transformation.js @@ -70,6 +70,7 @@ import { import {invalidateOnFileCreateToInternal, createInvalidations} from './utils'; import invariant from 'assert'; import {tracer, PluginTracer} from '@parcel/profiler'; +import {AssetFlags} from './types'; type GenerateFunc = (input: UncommittedAsset) => Promise; @@ -176,7 +177,7 @@ export default class Transformation { let pipeline = await this.loadPipeline( this.request.filePath, - asset.value.isSource, + Boolean(asset.value.flags & AssetFlags.IS_SOURCE), asset.value.pipeline, ); let assets, error; @@ -290,7 +291,7 @@ export default class Transformation { if (asset.value.type !== initialType) { nextPipeline = await this.loadNextPipeline({ filePath: initialAsset.value.filePath, - isSource: asset.value.isSource, + isSource: Boolean(asset.value.flags & AssetFlags.IS_SOURCE), newType: asset.value.type, newPipeline: asset.value.pipeline, currentPipeline: pipeline, @@ -363,7 +364,7 @@ export default class Transformation { asset.value.type !== initialType && (await this.loadNextPipeline({ filePath: initialAsset.value.filePath, - isSource: asset.value.isSource, + isSource: Boolean(asset.value.flags & AssetFlags.IS_SOURCE), newType: asset.value.type, newPipeline: asset.value.pipeline, currentPipeline: pipeline, diff --git a/packages/core/core/src/UncommittedAsset.js b/packages/core/core/src/UncommittedAsset.js index 6ff5b13db77..285bd6bda6f 100644 --- a/packages/core/core/src/UncommittedAsset.js +++ b/packages/core/core/src/UncommittedAsset.js @@ -28,7 +28,7 @@ import {createDependency, mergeDependencies} from './Dependency'; import {mergeEnvironments} from './Environment'; import {PARCEL_VERSION} from './constants'; import {createAsset, createAssetIdFromOptions} from './assetUtils'; -import {BundleBehaviorNames} from './types'; +import {AssetFlags, BundleBehaviorNames} from './types'; import {invalidateOnFileCreateToInternal, createInvalidations} from './utils'; import {type ProjectPath, fromProjectPath} from './projectPath'; @@ -116,7 +116,9 @@ export default class UncommittedAsset { this.value.stats.size = size; } - this.value.isLargeBlob = this.content instanceof Readable; + if (this.content instanceof Readable) { + this.value.flags |= AssetFlags.LARGE_BLOB; + } this.value.committed = true; } @@ -367,8 +369,9 @@ export default class UncommittedAsset { ? null : BundleBehaviorNames[this.value.bundleBehavior]), isBundleSplittable: - result.isBundleSplittable ?? this.value.isBundleSplittable, - isSource: this.value.isSource, + result.isBundleSplittable ?? + Boolean(this.value.flags & AssetFlags.IS_BUNDLE_SPLITTABLE), + isSource: Boolean(this.value.flags & AssetFlags.IS_SOURCE), env: mergeEnvironments( this.options.projectRoot, this.value.env, @@ -391,7 +394,9 @@ export default class UncommittedAsset { }, // $FlowFixMe symbols: result.symbols, - sideEffects: result.sideEffects ?? this.value.sideEffects, + sideEffects: + result.sideEffects ?? + Boolean(this.value.flags & AssetFlags.SIDE_EFFECTS), uniqueKey: result.uniqueKey, astGenerator: result.ast ? {type: result.ast.type, version: result.ast.version} diff --git a/packages/core/core/src/assetUtils.js b/packages/core/core/src/assetUtils.js index b55f3993704..e8c686ec308 100644 --- a/packages/core/core/src/assetUtils.js +++ b/packages/core/core/src/assetUtils.js @@ -37,7 +37,7 @@ import { fromProjectPathRelative, } from './projectPath'; import {hashString} from '@parcel/rust'; -import {BundleBehavior as BundleBehaviorMap} from './types'; +import {AssetFlags, BundleBehavior as BundleBehaviorMap} from './types'; import {PluginTracer} from '@parcel/profiler'; type AssetOptions = {| @@ -91,6 +91,15 @@ export function createAsset( projectRoot: FilePath, options: AssetOptions, ): Asset { + let { + shouldWrap, + hasCJSExports, + staticExports, + isConstantModule, + has_node_replacements, + ...meta + } = options.meta ?? {}; + return { id: options.id != null ? options.id : createAssetIdFromOptions(options), committed: options.committed ?? false, @@ -98,19 +107,28 @@ export function createAsset( query: options.query, bundleBehavior: options.bundleBehavior ? BundleBehaviorMap[options.bundleBehavior] - : null, - isBundleSplittable: options.isBundleSplittable ?? true, + : 255, + flags: + (options.isBundleSplittable ?? true + ? AssetFlags.IS_BUNDLE_SPLITTABLE + : 0) | + (options.isSource ? AssetFlags.IS_SOURCE : 0) | + (options.sideEffects ?? true ? AssetFlags.SIDE_EFFECTS : 0) | + (shouldWrap === true ? AssetFlags.SHOULD_WRAP : 0) | + (hasCJSExports === true ? AssetFlags.HAS_CJS_EXPORTS : 0) | + (staticExports === true ? AssetFlags.STATIC_EXPORTS : 0) | + (isConstantModule === true ? AssetFlags.IS_CONSTANT_MODULE : 0) | + (has_node_replacements === true ? AssetFlags.HAS_NODE_REPLACEMENTS : 0), type: options.type, contentKey: options.contentKey, mapKey: options.mapKey, astKey: options.astKey, astGenerator: options.astGenerator, dependencies: options.dependencies || new Map(), - isSource: options.isSource, outputHash: options.outputHash, pipeline: options.pipeline, env: options.env, - meta: options.meta || {}, + meta, stats: options.stats, symbols: options.symbols && @@ -124,7 +142,6 @@ export function createAsset( }, ]), ), - sideEffects: options.sideEffects ?? true, uniqueKey: options.uniqueKey, plugin: options.plugin, configPath: options.configPath, diff --git a/packages/core/core/src/dumpGraphToGraphViz.js b/packages/core/core/src/dumpGraphToGraphViz.js index 073ad38a414..8ed389cd1b4 100644 --- a/packages/core/core/src/dumpGraphToGraphViz.js +++ b/packages/core/core/src/dumpGraphToGraphViz.js @@ -9,7 +9,7 @@ import {requestGraphEdgeTypes} from './RequestTracker'; import path from 'path'; import {fromNodeId} from '@parcel/graph'; import {fromProjectPathRelative} from './projectPath'; -import {SpecifierType, Priority} from './types'; +import {SpecifierType, Priority, EnvironmentContextNames} from './types'; const COLORS = { root: 'gray', @@ -231,9 +231,13 @@ function nodeId(id) { function getEnvDescription(env: Environment) { let description; if (typeof env.engines.browsers === 'string') { - description = `${env.context}: ${env.engines.browsers}`; + description = `${EnvironmentContextNames[env.context]}: ${ + env.engines.browsers + }`; } else if (Array.isArray(env.engines.browsers)) { - description = `${env.context}: ${env.engines.browsers.join(', ')}`; + description = `${ + EnvironmentContextNames[env.context] + }: ${env.engines.browsers.join(', ')}`; } else if (env.engines.node) { description = `node: ${env.engines.node}`; } else if (env.engines.electron) { diff --git a/packages/core/core/src/public/Asset.js b/packages/core/core/src/public/Asset.js index 8f159925252..97d0919fa0e 100644 --- a/packages/core/core/src/public/Asset.js +++ b/packages/core/core/src/public/Asset.js @@ -32,6 +32,7 @@ import CommittedAsset from '../CommittedAsset'; import {createEnvironment} from '../Environment'; import {fromProjectPath, toProjectPath} from '../projectPath'; import { + AssetFlags, BundleBehavior as BundleBehaviorMap, BundleBehaviorNames, } from '../types'; @@ -123,7 +124,55 @@ class BaseAsset { } get meta(): Meta { - return this.#asset.value.meta; + return new Proxy(this.#asset.value.meta, { + get: (target, prop) => { + let flags = this.#asset.value.flags; + switch (prop) { + case 'shouldWrap': + return Boolean(flags & AssetFlags.SHOULD_WRAP); + case 'isConstantModule': + return Boolean(flags & AssetFlags.IS_CONSTANT_MODULE); + case 'has_node_replacements': + return Boolean(flags & AssetFlags.HAS_NODE_REPLACEMENTS); + case 'hasCJSExports': + return Boolean(flags & AssetFlags.HAS_CJS_EXPORTS); + case 'staticExports': + return Boolean(flags & AssetFlags.STATIC_EXPORTS); + default: + return target[prop]; + } + }, + set: (target, prop, value) => { + let flag; + switch (prop) { + case 'shouldWrap': + flag = AssetFlags.SHOULD_WRAP; + break; + case 'isConstantModule': + flag = AssetFlags.IS_CONSTANT_MODULE; + break; + case 'has_node_replacements': + flag = AssetFlags.HAS_NODE_REPLACEMENTS; + break; + case 'hasCJSExports': + flag = AssetFlags.HAS_CJS_EXPORTS; + break; + case 'staticExports': + flag = AssetFlags.STATIC_EXPORTS; + break; + default: + target[prop] = value; + return true; + } + + if (value) { + this.#asset.value.flags |= flag; + } else { + this.#asset.value.flags &= ~flag; + } + return true; + }, + }); } get bundleBehavior(): ?BundleBehavior { @@ -132,15 +181,15 @@ class BaseAsset { } get isBundleSplittable(): boolean { - return this.#asset.value.isBundleSplittable; + return Boolean(this.#asset.value.flags & AssetFlags.IS_BUNDLE_SPLITTABLE); } get isSource(): boolean { - return this.#asset.value.isSource; + return Boolean(this.#asset.value.flags & AssetFlags.IS_SOURCE); } get sideEffects(): boolean { - return this.#asset.value.sideEffects; + return Boolean(this.#asset.value.flags & AssetFlags.SIDE_EFFECTS); } get symbols(): IAssetSymbols { @@ -258,23 +307,31 @@ export class MutableAsset extends BaseAsset implements IMutableAsset { set bundleBehavior(bundleBehavior: ?BundleBehavior): void { this.#asset.value.bundleBehavior = bundleBehavior ? BundleBehaviorMap[bundleBehavior] - : null; + : 255; } get isBundleSplittable(): boolean { - return this.#asset.value.isBundleSplittable; + return Boolean(this.#asset.value.flags & AssetFlags.IS_BUNDLE_SPLITTABLE); } set isBundleSplittable(isBundleSplittable: boolean): void { - this.#asset.value.isBundleSplittable = isBundleSplittable; + if (isBundleSplittable) { + this.#asset.value.flags |= AssetFlags.IS_BUNDLE_SPLITTABLE; + } else { + this.#asset.value.flags &= ~AssetFlags.IS_BUNDLE_SPLITTABLE; + } } get sideEffects(): boolean { - return this.#asset.value.sideEffects; + return Boolean(this.#asset.value.flags & AssetFlags.SIDE_EFFECTS); } set sideEffects(sideEffects: boolean): void { - this.#asset.value.sideEffects = sideEffects; + if (sideEffects) { + this.#asset.value.flags |= AssetFlags.SIDE_EFFECTS; + } else { + this.#asset.value.flags &= ~AssetFlags.SIDE_EFFECTS; + } } get uniqueKey(): ?string { diff --git a/packages/core/core/src/public/Dependency.js b/packages/core/core/src/public/Dependency.js index bc060fbece2..330484d6fd6 100644 --- a/packages/core/core/src/public/Dependency.js +++ b/packages/core/core/src/public/Dependency.js @@ -11,7 +11,7 @@ import type { BundleBehavior, } from '@parcel/types'; import type {Dependency as InternalDependency, ParcelOptions} from '../types'; -import {BundleBehaviorNames} from '../types'; +import {BundleBehaviorNames, DependencyFlags} from '../types'; import nullthrows from 'nullthrows'; import Environment from './Environment'; @@ -88,20 +88,20 @@ export default class Dependency implements IDependency { } get needsStableName(): boolean { - return this.#dep.needsStableName; + return Boolean(this.#dep.flags & DependencyFlags.NEEDS_STABLE_NAME); } get bundleBehavior(): ?BundleBehavior { let bundleBehavior = this.#dep.bundleBehavior; - return bundleBehavior == null ? null : BundleBehaviorNames[bundleBehavior]; + return bundleBehavior == 255 ? null : BundleBehaviorNames[bundleBehavior]; } get isEntry(): boolean { - return this.#dep.isEntry; + return Boolean(this.#dep.flags & DependencyFlags.ENTRY); } get isOptional(): boolean { - return this.#dep.isOptional; + return Boolean(this.#dep.flags & DependencyFlags.OPTIONAL); } get loc(): ?SourceLocation { @@ -130,7 +130,67 @@ export default class Dependency implements IDependency { } get meta(): Meta { - return this.#dep.meta; + return new Proxy(this.#dep.meta, { + get: (target, prop) => { + let flags = this.#dep.flags; + switch (prop) { + case 'isESM': + return Boolean(flags & DependencyFlags.IS_ESM); + case 'shouldWrap': + return Boolean(flags & DependencyFlags.SHOULD_WRAP); + case 'webworker': + return Boolean(flags & DependencyFlags.IS_WEBWORKER); + case 'placeholder': + return this.#dep.placeholder; + case 'promiseSymbol': + return this.#dep.promiseSymbol; + case 'importAttributes': + if (!this.#dep.importAttributes) { + return {}; + } + return Object.fromEntries( + [...this.#dep.importAttributes].map(v => [v.key, v.value]), + ); + default: + return target[prop]; + } + }, + set: (target, prop, value) => { + let flag; + switch (prop) { + case 'isESM': + flag = DependencyFlags.IS_ESM; + break; + case 'shouldWrap': + flag = DependencyFlags.SHOULD_WRAP; + break; + case 'webworker': + flag = DependencyFlags.IS_WEBWORKER; + break; + case 'placeholder': + this.#dep.placeholder = value; + return true; + case 'promiseSymbol': + this.#dep.promiseSymbol = value; + return true; + case 'importAttributes': + this.#dep.importAttributes = Object.entries(value).map( + ([k, v]) => ({key: k, value: (v: any)}), + ); + return true; + default: + target[prop] = value; + return true; + } + + if (value) { + this.#dep.flags |= flag; + } else { + this.#dep.flags &= ~flag; + } + return true; + }, + }); } get symbols(): IMutableDependencySymbols { diff --git a/packages/core/core/src/public/Environment.js b/packages/core/core/src/public/Environment.js index 8123280447d..5bca97ffd12 100644 --- a/packages/core/core/src/public/Environment.js +++ b/packages/core/core/src/public/Environment.js @@ -16,6 +16,12 @@ import nullthrows from 'nullthrows'; import browserslist from 'browserslist'; import semver from 'semver'; import {fromInternalSourceLocation} from '../utils'; +import { + EnvironmentContextNames, + EnvironmentFlags, + OutputFormatNames, + SourceTypeNames, +} from '../types'; const inspect = Symbol.for('nodejs.util.inspect.custom'); @@ -174,7 +180,7 @@ export default class Environment implements IEnvironment { } get context(): EnvironmentContext { - return this.#environment.context; + return EnvironmentContextNames[this.#environment.context]; } get engines(): Engines { @@ -189,23 +195,25 @@ export default class Environment implements IEnvironment { } get outputFormat(): OutputFormat { - return this.#environment.outputFormat; + return OutputFormatNames[this.#environment.outputFormat]; } get sourceType(): SourceType { - return this.#environment.sourceType; + return SourceTypeNames[this.#environment.sourceType]; } get isLibrary(): boolean { - return this.#environment.isLibrary; + return Boolean(this.#environment.flags & EnvironmentFlags.IS_LIBRARY); } get shouldOptimize(): boolean { - return this.#environment.shouldOptimize; + return Boolean(this.#environment.flags & EnvironmentFlags.SHOULD_OPTIMIZE); } get shouldScopeHoist(): boolean { - return this.#environment.shouldScopeHoist; + return Boolean( + this.#environment.flags & EnvironmentFlags.SHOULD_SCOPE_HOIST, + ); } get sourceMap(): ?TargetSourceMapOptions { @@ -221,31 +229,31 @@ export default class Environment implements IEnvironment { // $FlowFixMe[unsupported-syntax] [inspect](): string { - return `Env(${this.#environment.context})`; + return `Env(${this.context})`; } isBrowser(): boolean { - return BROWSER_ENVS.has(this.#environment.context); + return BROWSER_ENVS.has(this.context); } isNode(): boolean { - return NODE_ENVS.has(this.#environment.context); + return NODE_ENVS.has(this.context); } isElectron(): boolean { - return ELECTRON_ENVS.has(this.#environment.context); + return ELECTRON_ENVS.has(this.context); } isIsolated(): boolean { - return ISOLATED_ENVS.has(this.#environment.context); + return ISOLATED_ENVS.has(this.context); } isWorker(): boolean { - return WORKER_ENVS.has(this.#environment.context); + return WORKER_ENVS.has(this.context); } isWorklet(): boolean { - return this.#environment.context === 'worklet'; + return this.context === 'worklet'; } matchesEngines( diff --git a/packages/core/core/src/requests/AssetGraphRequest.js b/packages/core/core/src/requests/AssetGraphRequest.js index 9c79e87da3f..a447c009d89 100644 --- a/packages/core/core/src/requests/AssetGraphRequest.js +++ b/packages/core/core/src/requests/AssetGraphRequest.js @@ -23,7 +23,7 @@ import nullthrows from 'nullthrows'; import {PromiseQueue, setEqual} from '@parcel/utils'; import {hashString} from '@parcel/rust'; import ThrowableDiagnostic from '@parcel/diagnostic'; -import {Priority} from '../types'; +import {DependencyFlags, Priority} from '../types'; import AssetGraph from '../AssetGraph'; import {PARCEL_VERSION} from '../constants'; import createEntryRequest from './EntryRequest'; @@ -380,7 +380,11 @@ export class AssetGraphBuilder { } else if (!node.requested) { let isAsyncChild = this.assetGraph .getIncomingDependencies(node.value) - .every(dep => dep.isEntry || dep.priority !== Priority.sync); + .every( + dep => + dep.flags & DependencyFlags.ENTRY || + dep.priority !== Priority.sync, + ); if (isAsyncChild) { node.requested = !isNodeLazy; } else { diff --git a/packages/core/core/src/requests/TargetRequest.js b/packages/core/core/src/requests/TargetRequest.js index 35f1171e11a..ce4fd34ac25 100644 --- a/packages/core/core/src/requests/TargetRequest.js +++ b/packages/core/core/src/requests/TargetRequest.js @@ -49,6 +49,7 @@ import {BROWSER_ENVS} from '../public/Environment'; import {optionsProxy, toInternalSourceLocation} from '../utils'; import {fromProjectPath, toProjectPath, joinProjectPath} from '../projectPath'; import {requestTypes} from '../RequestTracker'; +import {EnvironmentContextNames, EnvironmentFlags} from '../types'; type RunOpts = {| input: Entry, @@ -338,7 +339,9 @@ export class TargetResolver { }, }); } - if (!BROWSER_ENVS.has(targets[0].env.context)) { + if ( + !BROWSER_ENVS.has(EnvironmentContextNames[targets[0].env.context]) + ) { throw new ThrowableDiagnostic({ diagnostic: { message: `Only browser targets are supported in serve mode`, @@ -1606,15 +1609,15 @@ async function debugResolvedTargets(input, targets, targetInfo, options) { )} **Context**: ${target.env.context} ${format(info.context)} **Engines**: ${engines || ''} ${format(info.engines)} - **Library Mode**: ${String(target.env.isLibrary)} ${format( - info.isLibrary, - )} + **Library Mode**: ${String( + Boolean(target.env.flags & EnvironmentFlags.IS_LIBRARY), + )} ${format(info.isLibrary)} **Include Node Modules**: ${includeNodeModules} ${format( info.includeNodeModules, )} - **Optimize**: ${String(target.env.shouldOptimize)} ${format( - info.shouldOptimize, - )}`, + **Optimize**: ${String( + Boolean(target.env.flags & EnvironmentFlags.SHOULD_OPTIMIZE), + )} ${format(info.shouldOptimize)}`, codeFrames: target.loc ? [ { diff --git a/packages/core/core/src/types.js b/packages/core/core/src/types.js index b355f968b09..fdb41b62c90 100644 --- a/packages/core/core/src/types.js +++ b/packages/core/core/src/types.js @@ -5,7 +5,6 @@ import type { ASTGenerator, BuildMode, Engines, - EnvironmentContext, EnvMap, FilePath, Glob, @@ -16,12 +15,11 @@ import type { ReporterEvent, SemverRange, ServerOptions, - SourceType, Stats, Symbol, TargetSourceMapOptions, ConfigResult, - OutputFormat, + OutputFormat as TOutputFormat, TargetDescriptor, HMROptions, DetailedReportOptions, @@ -63,21 +61,55 @@ export type ProcessedParcelConfig = {| export type Environment = {| id: string, - context: EnvironmentContext, + context: $Values, engines: Engines, includeNodeModules: | boolean | Array | {[PackageName]: boolean, ...}, - outputFormat: OutputFormat, - sourceType: SourceType, - isLibrary: boolean, - shouldOptimize: boolean, - shouldScopeHoist: boolean, + outputFormat: $Values, + sourceType: $Values, + flags: number, sourceMap: ?TargetSourceMapOptions, loc: ?InternalSourceLocation, |}; +export const EnvironmentFlags = { + IS_LIBRARY: 1 << 0, + SHOULD_OPTIMIZE: 1 << 1, + SHOULD_SCOPE_HOIST: 1 << 2, +}; + +export const OutputFormat = { + global: 0, + commonjs: 1, + esmodule: 2, +}; + +export const OutputFormatNames: Array<$Keys> = + Object.keys(OutputFormat); + +export const SourceType = { + module: 0, + script: 1, +}; + +export const SourceTypeNames: Array<$Keys> = + Object.keys(SourceType); + +export const EnvironmentContext = { + browser: 0, + 'web-worker': 1, + 'service-worker': 2, + worklet: 3, + node: 4, + 'electron-main': 5, + 'electron-renderer': 6, +}; + +export const EnvironmentContextNames: Array<$Keys> = + Object.keys(EnvironmentContext); + export type InternalSourceLocation = {| +filePath: ProjectPath, /** inclusive */ @@ -132,10 +164,10 @@ export type Dependency = {| specifier: DependencySpecifier, specifierType: $Values, priority: $Values, - needsStableName: boolean, - bundleBehavior: ?$Values, - isEntry: boolean, - isOptional: boolean, + flags: number, + placeholder?: ?string, + promiseSymbol?: ?string, + bundleBehavior: $Values, loc: ?InternalSourceLocation, env: Environment, packageConditions?: number, @@ -158,13 +190,29 @@ export type Dependency = {| |}, >, pipeline?: ?string, + importAttributes?: Array, |}; +export const DependencyFlags = { + ENTRY: 1 << 0, + OPTIONAL: 1 << 1, + NEEDS_STABLE_NAME: 1 << 2, + SHOULD_WRAP: 1 << 3, + IS_ESM: 1 << 4, + IS_WEBWORKER: 1 << 5, + HAS_SYMBOLS: 1 << 6, +}; + export const BundleBehavior = { inline: 0, isolated: 1, }; +export type ImportAttribute = {| + key: string, + value: boolean, +|}; + export const BundleBehaviorNames: Array<$Keys> = Object.keys(BundleBehavior); @@ -175,9 +223,8 @@ export type Asset = {| query: ?string, type: string, dependencies: Map, - bundleBehavior: ?$Values, - isBundleSplittable: boolean, - isSource: boolean, + bundleBehavior: $Values, + flags: number, env: Environment, meta: Meta, stats: Stats, @@ -191,14 +238,25 @@ export type Asset = {| Symbol, {|local: Symbol, loc: ?InternalSourceLocation, meta?: ?Meta|}, >, - sideEffects: boolean, uniqueKey: ?string, configPath?: ProjectPath, plugin: ?PackageName, configKeyPath?: string, - isLargeBlob?: boolean, |}; +export const AssetFlags = { + IS_SOURCE: 1 << 0, + SIDE_EFFECTS: 1 << 1, + IS_BUNDLE_SPLITTABLE: 1 << 2, + LARGE_BLOB: 1 << 3, + HAS_CJS_EXPORTS: 1 << 4, + STATIC_EXPORTS: 1 << 5, + SHOULD_WRAP: 1 << 6, + IS_CONSTANT_MODULE: 1 << 7, + HAS_NODE_REPLACEMENTS: 1 << 8, + HAS_SYMBOLS: 1 << 9, +}; + export type InternalGlob = ProjectPath; export type InternalFile = {| @@ -315,7 +373,7 @@ export type ParcelOptions = {| +publicUrl: string, +distDir?: ProjectPath, +engines?: Engines, - +outputFormat?: OutputFormat, + +outputFormat?: TOutputFormat, +isLibrary?: boolean, |}, diff --git a/packages/core/core/test/Environment.test.js b/packages/core/core/test/Environment.test.js index 67643f1e4e1..74b78f1d2ae 100644 --- a/packages/core/core/test/Environment.test.js +++ b/packages/core/core/test/Environment.test.js @@ -6,37 +6,33 @@ import {createEnvironment} from '../src/Environment'; describe('Environment', () => { it('assigns a default environment with nothing passed', () => { assert.deepEqual(createEnvironment(), { - id: 'c242f987e3544367', - context: 'browser', + id: '788187fcd358de46', + context: 0, engines: { browsers: ['> 0.25%'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: undefined, loc: undefined, - sourceType: 'module', + sourceType: 0, }); }); it('assigns a node context if a node engine is given', () => { assert.deepEqual(createEnvironment({engines: {node: '>= 10.0.0'}}), { - id: '69e0ab7220ee8f7a', - context: 'node', + id: '2f10f79854f6b94b', + context: 4, engines: { node: '>= 10.0.0', }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 1, + flags: 0, sourceMap: undefined, loc: undefined, - sourceType: 'module', + sourceType: 0, }); }); @@ -44,56 +40,50 @@ describe('Environment', () => { assert.deepEqual( createEnvironment({engines: {browsers: ['last 1 version']}}), { - id: '4b5c9005af8c5b19', - context: 'browser', + id: '314954654e82feb3', + context: 0, engines: { browsers: ['last 1 version'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: undefined, loc: undefined, - sourceType: 'module', + sourceType: 0, }, ); }); it('assigns default engines for node', () => { assert.deepEqual(createEnvironment({context: 'node'}), { - id: 'f7c9644283a8698f', - context: 'node', + id: '81b1dde8607da1b5', + context: 4, engines: { node: '>= 8.0.0', }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 1, + flags: 0, sourceMap: undefined, loc: undefined, - sourceType: 'module', + sourceType: 0, }); }); it('assigns default engines for browsers', () => { assert.deepEqual(createEnvironment({context: 'browser'}), { - id: 'c242f987e3544367', - context: 'browser', + id: '788187fcd358de46', + context: 0, engines: { browsers: ['> 0.25%'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: undefined, loc: undefined, - sourceType: 'module', + sourceType: 0, }); }); }); diff --git a/packages/core/core/test/TargetRequest.test.js b/packages/core/core/test/TargetRequest.test.js index caeb37b1db7..1e02b4eee3d 100644 --- a/packages/core/core/test/TargetRequest.test.js +++ b/packages/core/core/test/TargetRequest.test.js @@ -125,19 +125,17 @@ describe('TargetResolver', () => { publicUrl: '/', distDir: normalizeSeparators(path.resolve('customA')), env: { - id: '1d40417b63734b32', - context: 'browser', + id: 'ebeaeb5c680f8c4f', + context: 0, includeNodeModules: true, engines: { browsers: ['> 0.25%'], }, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, }, { @@ -146,19 +144,17 @@ describe('TargetResolver', () => { distEntry: 'b.js', distDir: normalizeSeparators(path.resolve('customB')), env: { - id: '928f0d1c941b2e57', - context: 'node', + id: 'f4bd25724ba4f641', + context: 4, includeNodeModules: false, engines: { node: '>= 8.0.0', }, - outputFormat: 'commonjs', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 1, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, }, ], @@ -177,19 +173,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: 'b552bd32da37fa8b', - context: 'node', + id: '8da8f90dd22edc64', + context: 4, engines: { node: '>= 8.0.0', }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: true, - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 1, + flags: 5, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -211,21 +205,19 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: '8804e4eb97e2703e', - context: 'browser', + id: 'd062445afb902bbd', + context: 0, engines: { browsers: ['last 1 version'], }, includeNodeModules: false, - outputFormat: 'esmodule', - isLibrary: true, - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 2, + flags: 5, sourceMap: { inlineSources: true, }, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -247,19 +239,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/assets', env: { - id: 'a7ed3e73c53f1923', - context: 'browser', + id: '4dea6f5d061ef847', + context: 0, engines: { browsers: ['last 1 version'], }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: true, - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 1, + flags: 5, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -293,19 +283,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: 'f7c9644283a8698f', - context: 'node', + id: '81b1dde8607da1b5', + context: 4, engines: { node: '>= 8.0.0', }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 1, + flags: 0, sourceMap: undefined, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -336,19 +324,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: 'b552bd32da37fa8b', - context: 'node', + id: '8da8f90dd22edc64', + context: 4, engines: { node: '>= 8.0.0', }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: true, - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 1, + flags: 5, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -370,19 +356,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: '1f28e9ceaf633d83', - context: 'browser', + id: 'e9da10cde4f3ea10', + context: 0, engines: { browsers: ['last 1 version'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -404,19 +388,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: '767bf6e6b675c4f3', - context: 'browser', + id: 'dc8614216bb832dc', + context: 0, engines: { browsers: ['ie11'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -455,19 +437,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: 'b552bd32da37fa8b', - context: 'node', + id: '8da8f90dd22edc64', + context: 4, engines: { node: '>= 8.0.0', }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: true, - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 1, + flags: 5, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -489,19 +469,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: 'ed7c0e65adee71c9', - context: 'browser', + id: 'efbc33e1298d8d31', + context: 0, engines: { browsers: ['last 1 version'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: true, - shouldScopeHoist: false, + outputFormat: 0, + flags: 2, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -523,19 +501,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: 'f7692543e59e4c0a', - context: 'browser', + id: '2713f02ea149891e', + context: 0, engines: { browsers: ['ie11'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: true, - shouldScopeHoist: false, + outputFormat: 0, + flags: 2, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -566,19 +542,17 @@ describe('TargetResolver', () => { distEntry: undefined, publicUrl: 'www', env: { - id: 'ddb6ac7c9a3a9178', - context: 'browser', + id: 'f674466050f0db8f', + context: 0, engines: { browsers: '> 0.25%', }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -621,19 +595,17 @@ describe('TargetResolver', () => { distDir: normalizeSeparators(path.resolve('customB')), publicUrl: '/', env: { - id: '1d40417b63734b32', - context: 'browser', + id: 'ebeaeb5c680f8c4f', + context: 0, engines: { browsers: ['> 0.25%'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, }, ], @@ -663,19 +635,17 @@ describe('TargetResolver', () => { distDir: normalizeSeparators(path.resolve('customA')), publicUrl: '/', env: { - id: '1d40417b63734b32', - context: 'browser', + id: 'ebeaeb5c680f8c4f', + context: 0, engines: { browsers: ['> 0.25%'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, source: 'customA/index.js', }, @@ -692,8 +662,8 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: '6aafdb9eaa4a3812', - context: 'node', + id: '73ec4b016d461abc', + context: 4, engines: { browsers: [ 'last 1 Chrome version', @@ -703,13 +673,11 @@ describe('TargetResolver', () => { ], }, includeNodeModules: false, - isLibrary: true, - outputFormat: 'commonjs', - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 1, + flags: 5, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative(path.join(CONTEXT_FIXTURE_PATH, 'package.json')), @@ -1070,8 +1038,8 @@ describe('TargetResolver', () => { distEntry: 'index.mjs', publicUrl: '/', env: { - id: '439701173a9199ea', - context: 'browser', + id: 'a30b733cec75c314', + context: 0, engines: { browsers: [ 'last 1 Chrome version', @@ -1081,13 +1049,11 @@ describe('TargetResolver', () => { ], }, includeNodeModules: true, - outputFormat: 'esmodule', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 2, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative(path.join(fixture, 'package.json')), @@ -1115,8 +1081,8 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: '439701173a9199ea', - context: 'browser', + id: 'a30b733cec75c314', + context: 0, engines: { browsers: [ 'last 1 Chrome version', @@ -1126,13 +1092,11 @@ describe('TargetResolver', () => { ], }, includeNodeModules: true, - outputFormat: 'esmodule', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 2, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative(path.join(fixture, 'package.json')), @@ -1164,19 +1128,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/', env: { - id: 'b552bd32da37fa8b', - context: 'node', + id: '8da8f90dd22edc64', + context: 4, engines: { node: '>= 8.0.0', }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: true, - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 1, + flags: 5, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -1198,19 +1160,17 @@ describe('TargetResolver', () => { distEntry: 'index.js', publicUrl: '/assets', env: { - id: 'a7ed3e73c53f1923', - context: 'browser', + id: '4dea6f5d061ef847', + context: 0, engines: { browsers: ['last 1 version'], }, includeNodeModules: false, - outputFormat: 'commonjs', - isLibrary: true, - shouldOptimize: false, - shouldScopeHoist: true, + outputFormat: 1, + flags: 5, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -1246,8 +1206,8 @@ describe('TargetResolver', () => { distDir: '.parcel-cache/dist', publicUrl: '/', env: { - id: 'd6ea1d42532a7575', - context: 'browser', + id: '00d1d0d64778b6f2', + context: 0, engines: { browsers: [ 'last 1 Chrome version', @@ -1257,13 +1217,11 @@ describe('TargetResolver', () => { ], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, }, ], @@ -1283,19 +1241,17 @@ describe('TargetResolver', () => { ), publicUrl: '/', env: { - id: 'a9c07d094d038c73', - context: 'browser', + id: 'de832a9db5707a5a', + context: 0, engines: { browsers: ['Chrome 80'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, }, ], @@ -1316,19 +1272,17 @@ describe('TargetResolver', () => { distEntry: undefined, publicUrl: '/', env: { - id: 'a9c07d094d038c73', - context: 'browser', + id: 'de832a9db5707a5a', + context: 0, engines: { browsers: ['Chrome 80'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -1366,19 +1320,17 @@ describe('TargetResolver', () => { distEntry: undefined, publicUrl: '/', env: { - id: '1f28e9ceaf633d83', - context: 'browser', + id: 'e9da10cde4f3ea10', + context: 0, engines: { browsers: ['last 1 version'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( @@ -1406,19 +1358,17 @@ describe('TargetResolver', () => { distEntry: undefined, publicUrl: '/', env: { - id: '824e113c03cab3c8', - context: 'browser', + id: 'c8a9da03abcc3247', + context: 0, engines: { browsers: ['IE 11'], }, includeNodeModules: true, - outputFormat: 'global', - isLibrary: false, - shouldOptimize: false, - shouldScopeHoist: false, + outputFormat: 0, + flags: 0, sourceMap: {}, loc: undefined, - sourceType: 'module', + sourceType: 0, }, loc: { filePath: relative( diff --git a/packages/core/integration-tests/test/bundler.js b/packages/core/integration-tests/test/bundler.js index c72d44b2f3f..fda98450dad 100644 --- a/packages/core/integration-tests/test/bundler.js +++ b/packages/core/integration-tests/test/bundler.js @@ -1756,13 +1756,13 @@ describe('bundler', function () { assets: ['index.html'], }, { - assets: ['a.js', 'i.js'], + assets: ['a.js', 'b.js', 'd.js', 'h.js', 'i.js'], }, { - assets: ['vendor.js', 'b.js', 'j.js'], + assets: ['j.js'], }, { - assets: ['c.js', 'd.js', 'e.js', 'f.js', 'g.js', 'h.js'], + assets: ['c.js', 'e.js', 'f.js', 'g.js', 'vendor.js'], }, { assets: ['esmodule-helpers.js', 'index.js'], diff --git a/packages/core/integration-tests/test/javascript.js b/packages/core/integration-tests/test/javascript.js index e1d9c7839f8..c68632a5593 100644 --- a/packages/core/integration-tests/test/javascript.js +++ b/packages/core/integration-tests/test/javascript.js @@ -4667,7 +4667,7 @@ describe('javascript', function () { b.getBundles().find(b => b.type === 'js').filePath, 'utf8', ); - assert(dist.includes('$cPUKg$lodash = require("lodash");')); + assert(dist.includes('$4tAd3$lodash = require("lodash");')); let add = await run(b); assert.equal(add(2, 3), 5); @@ -4687,7 +4687,7 @@ describe('javascript', function () { assert( dist.includes( - 'const add = require(`lodash/${$8cad8166811e0063$var$fn}`);', + 'const add = require(`lodash/${$b4fd1a594eed7898$var$fn}`);', ), ); diff --git a/packages/core/integration-tests/test/sourcemaps.js b/packages/core/integration-tests/test/sourcemaps.js index 39040fd4a4e..571c9ca6a88 100644 --- a/packages/core/integration-tests/test/sourcemaps.js +++ b/packages/core/integration-tests/test/sourcemaps.js @@ -448,7 +448,7 @@ describe('sourcemaps', function () { source: inputs[0], generated: raw, str: 'const local', - generatedStr: 'let o', + generatedStr: 'let t', sourcePath: 'index.js', }); @@ -457,7 +457,7 @@ describe('sourcemaps', function () { source: inputs[0], generated: raw, str: 'local.a', - generatedStr: 'o.a', + generatedStr: 't.a', sourcePath: 'index.js', }); @@ -466,7 +466,7 @@ describe('sourcemaps', function () { source: inputs[1], generated: raw, str: 'exports.a', - generatedStr: 't.a', + generatedStr: 'o.a', sourcePath: 'local.js', }); @@ -475,7 +475,7 @@ describe('sourcemaps', function () { source: inputs[2], generated: raw, str: 'exports.count = function(a, b) {', - generatedStr: 't.count=function(e,n){', + generatedStr: 'o.count=function(e,n){', sourcePath: 'utils/util.js', }); });