@parcel/core
Advanced tools
Comparing version 2.0.0-nightly.77 to 2.0.0-nightly.83
@@ -236,2 +236,8 @@ "use strict"; | ||
return; | ||
} // Don't deduplicate when context changes | ||
if (node.value.env.context !== bundle.env.context) { | ||
actions.skipChildren(); | ||
return; | ||
} | ||
@@ -342,26 +348,2 @@ | ||
getBundleGroupsReferencedByBundle(bundle) { | ||
let node = (0, _nullthrows.default)(this._graph.getNode(bundle.id), 'Bundle graph must contain bundle'); | ||
let groupNodes = []; | ||
this._graph.traverse((node, context, actions) => { | ||
if (node.type === 'bundle_group') { | ||
groupNodes.push(node); | ||
actions.skipChildren(); | ||
} | ||
}, node, 'bundle'); | ||
return (0, _utils.flatMap)(groupNodes, groupNode => { | ||
return this._graph.getNodesConnectedTo(groupNode).filter(node => node.type === 'dependency' && this._graph.hasEdge(bundle.id, node.id, 'contains')).map(dependencyNode => { | ||
// TODO: Enforce non-null when bundle groups have the correct bundles | ||
// pointing to them | ||
(0, _assert.default)(dependencyNode.type === 'dependency'); | ||
return { | ||
bundleGroup: groupNode.value, | ||
dependency: dependencyNode.value | ||
}; | ||
}); | ||
}); | ||
} | ||
getIncomingDependencies(asset) { | ||
@@ -368,0 +350,0 @@ let node = this._graph.getNode(asset.id); |
@@ -39,2 +39,3 @@ "use strict"; | ||
isURL: (_opts$isURL = opts.isURL) !== null && _opts$isURL !== void 0 ? _opts$isURL : false, | ||
isDeferred: false, | ||
meta: opts.meta || {}, | ||
@@ -41,0 +42,0 @@ symbols: opts.symbols || new Map() |
@@ -80,12 +80,25 @@ "use strict"; | ||
getBundleGroupsReferencedByBundle(bundle) { | ||
return _classPrivateFieldGet(this, _graph).getBundleGroupsReferencedByBundle((0, _Bundle.bundleToInternalBundle)(bundle)).map(({ | ||
bundleGroup, | ||
dependency | ||
}) => ({ | ||
bundleGroup, | ||
dependency: new _Dependency.default(dependency) | ||
})); | ||
getExternalDependencies(bundle) { | ||
let externalDependencies = []; | ||
_classPrivateFieldGet(this, _graph).traverseBundle((0, _Bundle.bundleToInternalBundle)(bundle), node => { | ||
if (node.type === 'dependency' && (_classPrivateFieldGet(this, _graph).getDependencyResolution(node.value) == null || _classPrivateFieldGet(this, _graph)._graph.getNodesConnectedFrom(node).find(node => node.type === 'bundle_group'))) { | ||
externalDependencies.push(new _Dependency.default(node.value)); | ||
} | ||
}); | ||
return externalDependencies; | ||
} | ||
resolveExternalDependency(dependency) { | ||
let node = _classPrivateFieldGet(this, _graph)._graph.getNodesConnectedFrom((0, _nullthrows.default)(_classPrivateFieldGet(this, _graph)._graph.getNode(dependency.id))).find(node => node.type === 'bundle_group'); | ||
if (node == null) { | ||
return; | ||
} | ||
(0, _assert.default)(node.type === 'bundle_group'); | ||
return node.value; | ||
} | ||
getDependencies(asset) { | ||
@@ -92,0 +105,0 @@ return _classPrivateFieldGet(this, _graph).getDependencies((0, _Asset.assetToInternalAsset)(asset).value).map(dep => new _Dependency.default(dep)); |
@@ -68,2 +68,6 @@ "use strict"; | ||
get isDeferred() { | ||
return _classPrivateFieldGet(this, _dep).isDeferred; | ||
} | ||
get loc() { | ||
@@ -70,0 +74,0 @@ return _classPrivateFieldGet(this, _dep).loc; |
@@ -256,2 +256,3 @@ "use strict"; | ||
let defer = this.shouldDeferDependency(dependency, assetGroup.sideEffects); | ||
dependency.isDeferred = defer; | ||
let assetGroupNode = (0, _AssetGraph.nodeFromAssetGroup)(assetGroup, defer); | ||
@@ -276,2 +277,7 @@ let existingAssetGroupNode = this.assetGraph.getNode(assetGroupNode.id); | ||
if (node.type === 'dependency' && !node.value.isDeferred) { | ||
actions.skipChildren(); | ||
return; | ||
} | ||
if (node.type == 'asset_group') { | ||
@@ -281,2 +287,3 @@ (0, _assert.default)(parent && parent.type === 'dependency'); | ||
if (node.deferred && !this.shouldDeferDependency(parent.value, node.value.sideEffects)) { | ||
parent.value.isDeferred = false; | ||
node.deferred = false; | ||
@@ -283,0 +290,0 @@ this.assetGraph.markIncomplete(node); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = exports.ENGINES_SCHEMA = void 0; | ||
exports.COMMON_TARGET_DESCRIPTOR_SCHEMA = exports.DESCRIPTOR_SCHEMA = exports.ENGINES_SCHEMA = void 0; | ||
const ENGINES_SCHEMA = { | ||
@@ -28,3 +28,3 @@ type: 'object', | ||
exports.ENGINES_SCHEMA = ENGINES_SCHEMA; | ||
var _default = { | ||
const DESCRIPTOR_SCHEMA = { | ||
type: 'object', | ||
@@ -89,2 +89,8 @@ properties: { | ||
}; | ||
exports.default = _default; | ||
exports.DESCRIPTOR_SCHEMA = DESCRIPTOR_SCHEMA; | ||
const COMMON_TARGET_DESCRIPTOR_SCHEMA = { | ||
oneOf: [DESCRIPTOR_SCHEMA, { | ||
enum: [false] | ||
}] | ||
}; | ||
exports.COMMON_TARGET_DESCRIPTOR_SCHEMA = COMMON_TARGET_DESCRIPTOR_SCHEMA; |
@@ -22,3 +22,3 @@ "use strict"; | ||
var _TargetDescriptor = _interopRequireWildcard(require("./TargetDescriptor.schema")); | ||
var _TargetDescriptor = require("./TargetDescriptor.schema"); | ||
@@ -273,3 +273,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if (typeof targetDist === 'string' || pkgTargets[targetName]) { | ||
var _descriptor$publicUrl, _descriptor$engines, _descriptor$context, _descriptor$includeNo, _descriptor$outputFor; | ||
var _pkgTargets$targetNam, _descriptor$publicUrl, _descriptor$engines, _descriptor$context, _descriptor$includeNo, _descriptor$outputFor; | ||
@@ -282,3 +282,3 @@ let distDir; | ||
let _descriptor = pkgTargets[targetName] || {}; | ||
let _descriptor = (_pkgTargets$targetNam = pkgTargets[targetName]) !== null && _pkgTargets$targetNam !== void 0 ? _pkgTargets$targetNam : {}; | ||
@@ -295,3 +295,4 @@ if (typeof targetDist === 'string') { | ||
let descriptor = parseDescriptor(targetName, _descriptor, pkgFilePath, pkgContents); | ||
let descriptor = parseCommonTargetDescriptor(targetName, _descriptor, pkgFilePath, pkgContents); | ||
if (!descriptor) continue; | ||
let isLibrary = typeof distEntry === 'string' ? _path.default.extname(distEntry) === '.js' : false; | ||
@@ -322,3 +323,2 @@ targets.set(targetName, { | ||
let _descriptor = pkgTargets[targetName]; | ||
let distPath = pkg[targetName]; | ||
@@ -362,6 +362,6 @@ let distDir; | ||
if (_descriptor) { | ||
if (targetName in pkgTargets) { | ||
var _descriptor$publicUrl2, _descriptor$engines2; | ||
let descriptor = parseDescriptor(targetName, _descriptor, pkgFilePath, pkgContents); | ||
let descriptor = parseDescriptor(targetName, pkgTargets[targetName], pkgFilePath, pkgContents); | ||
targets.set(targetName, { | ||
@@ -421,3 +421,3 @@ name: targetName, | ||
function parseDescriptor(targetName, descriptor, pkgPath, pkgContents) { | ||
_utils.validateSchema.diagnostic(_TargetDescriptor.default, descriptor, pkgPath, pkgContents, '@parcel/core', `/targets/${targetName}`, `Invalid target descriptor for target "${targetName}"`); // $FlowFixMe we just verified this | ||
_utils.validateSchema.diagnostic(_TargetDescriptor.DESCRIPTOR_SCHEMA, descriptor, pkgPath, pkgContents, '@parcel/core', `/targets/${targetName}`, `Invalid target descriptor for target "${targetName}"`); // $FlowFixMe we just verified this | ||
@@ -428,2 +428,9 @@ | ||
function parseCommonTargetDescriptor(targetName, descriptor, pkgPath, pkgContents) { | ||
_utils.validateSchema.diagnostic(_TargetDescriptor.COMMON_TARGET_DESCRIPTOR_SCHEMA, descriptor, pkgPath, pkgContents, '@parcel/core', `/targets/${targetName}`, `Invalid target descriptor for target "${targetName}"`); // $FlowFixMe we just verified this | ||
return descriptor; | ||
} | ||
function assertNoDuplicateTargets(targets, pkgFilePath, pkgContents) { | ||
@@ -430,0 +437,0 @@ // Detect duplicate targets by destination path and provide a nice error. |
{ | ||
"name": "@parcel/core", | ||
"version": "2.0.0-nightly.77+287ac639", | ||
"version": "2.0.0-nightly.83+e33d9161", | ||
"license": "MIT", | ||
@@ -19,13 +19,13 @@ "publishConfig": { | ||
"dependencies": { | ||
"@parcel/cache": "2.0.0-nightly.79+287ac639", | ||
"@parcel/diagnostic": "2.0.0-nightly.79+287ac639", | ||
"@parcel/events": "2.0.0-nightly.79+287ac639", | ||
"@parcel/fs": "2.0.0-nightly.79+287ac639", | ||
"@parcel/logger": "2.0.0-nightly.79+287ac639", | ||
"@parcel/package-manager": "2.0.0-nightly.79+287ac639", | ||
"@parcel/plugin": "2.0.0-nightly.79+287ac639", | ||
"@parcel/source-map": "2.0.0-nightly.79+287ac639", | ||
"@parcel/types": "2.0.0-nightly.79+287ac639", | ||
"@parcel/utils": "2.0.0-nightly.79+287ac639", | ||
"@parcel/workers": "2.0.0-nightly.79+287ac639", | ||
"@parcel/cache": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/diagnostic": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/events": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/fs": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/logger": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/package-manager": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/plugin": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/source-map": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/types": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/utils": "2.0.0-nightly.85+e33d9161", | ||
"@parcel/workers": "2.0.0-nightly.85+e33d9161", | ||
"abortcontroller-polyfill": "^1.1.9", | ||
@@ -46,3 +46,3 @@ "browserslist": "^4.6.6", | ||
}, | ||
"gitHead": "287ac6397ade28595d56ac73971edb832bda8ff7" | ||
"gitHead": "e33d91613d0ab9f600c93c5f8466f20fe9ca9dce" | ||
} |
@@ -15,3 +15,2 @@ // @flow strict-local | ||
BundleGraphNode, | ||
BundleGroupNode, | ||
Dependency, | ||
@@ -315,2 +314,8 @@ DependencyNode, | ||
// Don't deduplicate when context changes | ||
if (node.value.env.context !== bundle.env.context) { | ||
actions.skipChildren(); | ||
return; | ||
} | ||
if (this._graph.hasEdge(node.value.id, asset.id, 'contains')) { | ||
@@ -449,47 +454,2 @@ inBundle = true; | ||
getBundleGroupsReferencedByBundle( | ||
bundle: Bundle, | ||
): Array<{ | ||
bundleGroup: BundleGroup, | ||
dependency: Dependency, | ||
... | ||
}> { | ||
let node = nullthrows( | ||
this._graph.getNode(bundle.id), | ||
'Bundle graph must contain bundle', | ||
); | ||
let groupNodes: Array<BundleGroupNode> = []; | ||
this._graph.traverse( | ||
(node, context, actions) => { | ||
if (node.type === 'bundle_group') { | ||
groupNodes.push(node); | ||
actions.skipChildren(); | ||
} | ||
}, | ||
node, | ||
'bundle', | ||
); | ||
return flatMap(groupNodes, groupNode => { | ||
return this._graph | ||
.getNodesConnectedTo(groupNode) | ||
.filter( | ||
node => | ||
node.type === 'dependency' && | ||
this._graph.hasEdge(bundle.id, node.id, 'contains'), | ||
) | ||
.map(dependencyNode => { | ||
// TODO: Enforce non-null when bundle groups have the correct bundles | ||
// pointing to them | ||
invariant(dependencyNode.type === 'dependency'); | ||
return { | ||
bundleGroup: groupNode.value, | ||
dependency: dependencyNode.value, | ||
}; | ||
}); | ||
}); | ||
} | ||
getIncomingDependencies(asset: Asset): Array<Dependency> { | ||
@@ -496,0 +456,0 @@ let node = this._graph.getNode(asset.id); |
@@ -48,2 +48,3 @@ // @flow | ||
isURL: opts.isURL ?? false, | ||
isDeferred: false, | ||
meta: opts.meta || {}, | ||
@@ -50,0 +51,0 @@ symbols: opts.symbols || new Map(), |
@@ -53,2 +53,3 @@ // @flow | ||
if (node.value.isOptional) parts.push('optional'); | ||
if (node.value.isDeferred) parts.push('deferred'); | ||
if (parts.length) label += ' (' + parts.join(', ') + ')'; | ||
@@ -59,5 +60,3 @@ if (node.value.env) label += ` (${getEnvDescription(node.value.env)})`; | ||
} else if (node.type === 'asset_group') { | ||
if (node.deferred) { | ||
label += '(deferred)'; | ||
} | ||
if (node.deferred) label += '(deferred)'; | ||
} else if (node.type === 'file') { | ||
@@ -64,0 +63,0 @@ label += path.basename(node.value.filePath); |
@@ -73,16 +73,33 @@ // @flow strict-local | ||
getBundleGroupsReferencedByBundle( | ||
bundle: IBundle, | ||
): Array<{| | ||
bundleGroup: BundleGroup, | ||
dependency: IDependency, | ||
|}> { | ||
return this.#graph | ||
.getBundleGroupsReferencedByBundle(bundleToInternalBundle(bundle)) | ||
.map(({bundleGroup, dependency}) => ({ | ||
bundleGroup, | ||
dependency: new Dependency(dependency), | ||
})); | ||
getExternalDependencies(bundle: IBundle): Array<IDependency> { | ||
let externalDependencies = []; | ||
this.#graph.traverseBundle(bundleToInternalBundle(bundle), node => { | ||
if ( | ||
node.type === 'dependency' && | ||
(this.#graph.getDependencyResolution(node.value) == null || | ||
this.#graph._graph | ||
.getNodesConnectedFrom(node) | ||
.find(node => node.type === 'bundle_group')) | ||
) { | ||
externalDependencies.push(new Dependency(node.value)); | ||
} | ||
}); | ||
return externalDependencies; | ||
} | ||
resolveExternalDependency(dependency: IDependency): ?BundleGroup { | ||
let node = this.#graph._graph | ||
.getNodesConnectedFrom( | ||
nullthrows(this.#graph._graph.getNode(dependency.id)), | ||
) | ||
.find(node => node.type === 'bundle_group'); | ||
if (node == null) { | ||
return; | ||
} | ||
invariant(node.type === 'bundle_group'); | ||
return node.value; | ||
} | ||
getDependencies(asset: IAsset): Array<IDependency> { | ||
@@ -89,0 +106,0 @@ return this.#graph |
@@ -60,2 +60,6 @@ // @flow | ||
get isDeferred(): boolean { | ||
return this.#dep.isDeferred; | ||
} | ||
get loc(): ?SourceLocation { | ||
@@ -62,0 +66,0 @@ return this.#dep.loc; |
@@ -306,2 +306,3 @@ // @flow strict-local | ||
let defer = this.shouldDeferDependency(dependency, assetGroup.sideEffects); | ||
dependency.isDeferred = defer; | ||
@@ -316,2 +317,3 @@ let assetGroupNode = nodeFromAssetGroup(assetGroup, defer); | ||
this.assetGraph.resolveDependency(dependency, assetGroupNode); | ||
if (existingAssetGroupNode) { | ||
@@ -325,2 +327,7 @@ // Node already existed, that asset might have deferred dependencies, | ||
if (node.type === 'dependency' && !node.value.isDeferred) { | ||
actions.skipChildren(); | ||
return; | ||
} | ||
if (node.type == 'asset_group') { | ||
@@ -332,2 +339,3 @@ invariant(parent && parent.type === 'dependency'); | ||
) { | ||
parent.value.isDeferred = false; | ||
node.deferred = false; | ||
@@ -334,0 +342,0 @@ this.assetGraph.markIncomplete(node); |
@@ -27,3 +27,3 @@ // @flow strict-local | ||
export default ({ | ||
export const DESCRIPTOR_SCHEMA: SchemaEntity = { | ||
type: 'object', | ||
@@ -100,2 +100,11 @@ properties: { | ||
additionalProperties: false, | ||
}: SchemaEntity); | ||
}; | ||
export const COMMON_TARGET_DESCRIPTOR_SCHEMA: SchemaEntity = { | ||
oneOf: [ | ||
DESCRIPTOR_SCHEMA, | ||
{ | ||
enum: [false], | ||
}, | ||
], | ||
}; |
@@ -25,3 +25,7 @@ // @flow | ||
import invariant from 'assert'; | ||
import DESCRIPTOR_SCHEMA, {ENGINES_SCHEMA} from './TargetDescriptor.schema'; | ||
import { | ||
COMMON_TARGET_DESCRIPTOR_SCHEMA, | ||
DESCRIPTOR_SCHEMA, | ||
ENGINES_SCHEMA, | ||
} from './TargetDescriptor.schema'; | ||
@@ -287,3 +291,3 @@ export type TargetResolveResult = {| | ||
let _descriptor: mixed = pkgTargets[targetName] || {}; | ||
let _descriptor: mixed = pkgTargets[targetName] ?? {}; | ||
if (typeof targetDist === 'string') { | ||
@@ -300,3 +304,3 @@ distDir = path.resolve(pkgDir, path.dirname(targetDist)); | ||
let descriptor = parseDescriptor( | ||
let descriptor = parseCommonTargetDescriptor( | ||
targetName, | ||
@@ -307,2 +311,4 @@ _descriptor, | ||
); | ||
if (!descriptor) continue; | ||
let isLibrary = | ||
@@ -348,3 +354,2 @@ typeof distEntry === 'string' | ||
let _descriptor: mixed = pkgTargets[targetName]; | ||
let distPath: mixed = pkg[targetName]; | ||
@@ -393,6 +398,6 @@ let distDir; | ||
if (_descriptor) { | ||
if (targetName in pkgTargets) { | ||
let descriptor = parseDescriptor( | ||
targetName, | ||
_descriptor, | ||
pkgTargets[targetName], | ||
pkgFilePath, | ||
@@ -486,2 +491,22 @@ pkgContents, | ||
function parseCommonTargetDescriptor( | ||
targetName: string, | ||
descriptor: mixed, | ||
pkgPath: ?FilePath, | ||
pkgContents: string | mixed, | ||
): TargetDescriptor | PackageTargetDescriptor | false { | ||
validateSchema.diagnostic( | ||
COMMON_TARGET_DESCRIPTOR_SCHEMA, | ||
descriptor, | ||
pkgPath, | ||
pkgContents, | ||
'@parcel/core', | ||
`/targets/${targetName}`, | ||
`Invalid target descriptor for target "${targetName}"`, | ||
); | ||
// $FlowFixMe we just verified this | ||
return descriptor; | ||
} | ||
function assertNoDuplicateTargets(targets, pkgFilePath, pkgContents) { | ||
@@ -488,0 +513,0 @@ // Detect duplicate targets by destination path and provide a nice error. |
@@ -63,2 +63,3 @@ // @flow strict-local | ||
isWeak: ?boolean, | ||
isDeferred: boolean, | ||
loc: ?SourceLocation, | ||
@@ -65,0 +66,0 @@ env: Environment, |
@@ -16,2 +16,7 @@ // @flow | ||
const COMMON_TARGETS_IGNORE_FIXTURE_PATH = path.join( | ||
__dirname, | ||
'fixtures/common-targets-ignore', | ||
); | ||
const CUSTOM_TARGETS_FIXTURE_PATH = path.join( | ||
@@ -210,2 +215,52 @@ __dirname, | ||
it('allows ignoring common targets from package.json', async () => { | ||
let targetResolver = new TargetResolver(DEFAULT_OPTIONS); | ||
assert.deepEqual( | ||
await targetResolver.resolve(COMMON_TARGETS_IGNORE_FIXTURE_PATH), | ||
{ | ||
files: [ | ||
{ | ||
filePath: path.join( | ||
COMMON_TARGETS_IGNORE_FIXTURE_PATH, | ||
'package.json', | ||
), | ||
}, | ||
], | ||
targets: [ | ||
{ | ||
name: 'app', | ||
distDir: path.join(COMMON_TARGETS_IGNORE_FIXTURE_PATH, 'dist'), | ||
distEntry: 'index.js', | ||
publicUrl: '/', | ||
env: { | ||
context: 'node', | ||
engines: { | ||
node: '>= 8.0.0', | ||
}, | ||
includeNodeModules: false, | ||
outputFormat: 'commonjs', | ||
isLibrary: false, | ||
}, | ||
sourceMap: undefined, | ||
loc: { | ||
filePath: path.join( | ||
COMMON_TARGETS_IGNORE_FIXTURE_PATH, | ||
'package.json', | ||
), | ||
start: { | ||
column: 10, | ||
line: 3, | ||
}, | ||
end: { | ||
column: 24, | ||
line: 3, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
); | ||
}); | ||
it('resolves custom targets from package.json', async () => { | ||
@@ -212,0 +267,0 @@ let targetResolver = new TargetResolver(DEFAULT_OPTIONS); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
614407
121
17681