Skip to content

Commit

Permalink
Upgrade to Flow 0.112 (#3783)
Browse files Browse the repository at this point in the history
* Make bundler, dependency, and js transformer satisfy flow 0.112

* Make ParcelConfigFile and ResolvedParcelConfigFile strict object types

* FlowFixMe spreading meta

* Upgrade to flow 0.112
  • Loading branch information
Will Binns-Smith committed Nov 15, 2019
1 parent 4a3f534 commit 648146b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Expand Up @@ -35,4 +35,4 @@ untyped-import
untyped-type-import

[version]
0.110.1
0.112.0
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"doctoc": "^1.4.0",
"eslint": "^5.16.0",
"flow-bin": "0.110.1",
"flow-bin": "0.112.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"lerna": "^3.3.2",
Expand Down
19 changes: 13 additions & 6 deletions packages/bundlers/default/src/DefaultBundler.js
Expand Up @@ -31,6 +31,9 @@ export default new Bundler({
if (node.type !== 'dependency') {
return {
...context,
bundleGroup: context?.bundleGroup,
bundleByType: context?.bundleByType,
bundleGroupDependency: context?.bundleGroupDependency,
parentNode: node
};
}
Expand Down Expand Up @@ -72,14 +75,18 @@ export default new Bundler({
}

invariant(context != null);
invariant(context.parentNode.type === 'asset');
let bundleGroup = nullthrows(context.bundleGroup);
let bundleGroupDependency = nullthrows(context.bundleGroupDependency);
let bundleByType = nullthrows(context.bundleByType);

for (let asset of assets) {
invariant(context.parentNode.type === 'asset');
let parentAsset = context.parentNode.value;
if (parentAsset.type === asset.type) {
continue;
}

let existingBundle = context.bundleByType.get(asset.type);
let existingBundle = bundleByType.get(asset.type);
if (existingBundle) {
// If a bundle of this type has already been created in this group,
// merge this subgraph into it.
Expand All @@ -88,14 +95,14 @@ export default new Bundler({
} else {
let bundle = bundleGraph.createBundle({
entryAsset: asset,
target: context.bundleGroup.target,
isEntry: context.bundleGroupDependency.isEntry,
target: bundleGroup.target,
isEntry: bundleGroupDependency.isEntry,
isInline: asset.isInline
});
context.bundleByType.set(bundle.type, bundle);
bundleByType.set(bundle.type, bundle);
bundleRoots.set(bundle, [asset]);
bundleGraph.createAssetReference(dependency, asset);
bundleGraph.addBundleToBundleGroup(bundle, context.bundleGroup);
bundleGraph.addBundleToBundleGroup(bundle, bundleGroup);
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core/core/src/Dependency.js
Expand Up @@ -41,6 +41,10 @@ export function createDependency(opts: DependencyOpts): Dependency {
return {
...opts,
id,
isAsync: opts.isAsync ?? false,
isEntry: opts.isEntry ?? false,
isOptional: opts.isOptional ?? false,
isURL: opts.isURL ?? false,
meta: opts.meta || {},
symbols: opts.symbols || new Map()
};
Expand Down
6 changes: 5 additions & 1 deletion packages/core/core/src/InternalAsset.js
Expand Up @@ -288,7 +288,11 @@ export default class InternalAsset {
? new Map(this.value.dependencies)
: new Map(),
includedFiles: new Map(this.value.includedFiles),
meta: {...this.value.meta, ...result.meta},
meta: {
...this.value.meta,
// $FlowFixMe
...result.meta
},
pipeline:
result.pipeline ??
(this.value.type === result.type ? this.value.pipeline : null),
Expand Down
6 changes: 3 additions & 3 deletions packages/core/core/src/loadParcelConfig.js
Expand Up @@ -79,7 +79,7 @@ export async function readAndProcess(
}

export async function processConfig(
configFile: ParcelConfigFile,
configFile: ParcelConfigFile | ResolvedParcelConfigFile,
filePath: FilePath,
options: ParcelOptions
) {
Expand Down Expand Up @@ -126,7 +126,7 @@ export async function resolveExtends(
}

export function validateConfigFile(
config: ParcelConfigFile,
config: ParcelConfigFile | ResolvedParcelConfigFile,
relativePath: FilePath
) {
validateNotEmpty(config, relativePath);
Expand Down Expand Up @@ -173,7 +173,7 @@ export function validateConfigFile(
}

export function validateNotEmpty(
config: ParcelConfigFile,
config: ParcelConfigFile | ResolvedParcelConfigFile,
relativePath: FilePath
) {
assert.notDeepStrictEqual(config, {}, `${relativePath} can't be empty`);
Expand Down
13 changes: 6 additions & 7 deletions packages/core/types/index.js
Expand Up @@ -33,7 +33,7 @@ export type ModuleSpecifier = string;

export type GlobMap<T> = {[Glob]: T, ...};

export type ParcelConfigFile = {
export type ParcelConfigFile = {|
extends?: PackageName | FilePath | Array<PackageName | FilePath>,
resolvers?: Array<PackageName>,
transforms?: {[Glob]: Array<PackageName>, ...},
Expand All @@ -43,15 +43,14 @@ export type ParcelConfigFile = {
packagers?: {[Glob]: PackageName, ...},
optimizers?: {[Glob]: Array<PackageName>, ...},
reporters?: Array<PackageName>,
validators?: {[Glob]: Array<PackageName>, ...},
...
};
validators?: {[Glob]: Array<PackageName>, ...}
|};

export type ResolvedParcelConfigFile = {
export type ResolvedParcelConfigFile = {|
...ParcelConfigFile,
filePath: FilePath,
...
};
resolveFrom?: FilePath
|};

export type Engines = {
browsers?: string | Array<string>,
Expand Down
9 changes: 7 additions & 2 deletions packages/transformers/js/src/visitors/dependencies.js
Expand Up @@ -156,7 +156,11 @@ function evaluateExpression(node) {
return res;
}

function addDependency(asset, node, opts = {}) {
function addDependency(
asset,
node,
opts: ?{|isAsync?: boolean, isOptional?: boolean|}
) {
// If this came from an inline <script> tag, throw an error.
// TODO: run JSPackager on inline script tags.
// let inlineHTML =
Expand All @@ -172,7 +176,8 @@ function addDependency(asset, node, opts = {}) {
asset.addDependency({
moduleSpecifier: node.value,
loc: node.loc && node.loc.start,
...opts
isAsync: opts ? opts.isAsync : false,
isOptional: opts ? opts.isOptional : false
});
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -5677,10 +5677,10 @@ flatted@^2.0.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==

flow-bin@0.110.1:
version "0.110.1"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.110.1.tgz#24ac70bf0871a5d6bc181ba99801ded4d5e3b442"
integrity sha512-6FhvNKNvPQ523mx7sqNxTQvI/HgAWa/pbIsQuCst53qRqs387EFfYqgm4I3Zae5HLaVFacBwgWKmjKd92vf19w==
flow-bin@0.112.0:
version "0.112.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.112.0.tgz#6a21c31937c4a2f23a750056a364c598a95ea216"
integrity sha512-vdcuKv0UU55vjv0e2EVh1ZxlU+TSNT19SkE+6gT1vYzTKtzYE6dLuAmBIiS3Rg2N9D9HOI6TKSyl53zPtqZLrA==

flush-write-stream@^1.0.0, flush-write-stream@^1.0.2:
version "1.1.1"
Expand Down

0 comments on commit 648146b

Please sign in to comment.