Skip to content

Commit

Permalink
feat(migrate): CCP to SCP - fix minChunks, test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvdutt committed Aug 20, 2018
1 parent b68a7d0 commit e404f3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-0" da
name: 'app',
chunks: 'initial',
enforce: true,
minChunks: 2,
test: 'app'
},
vendor: {
name: 'vendor',
chunks: 'initial',
enforce: true,
minChunks: 2,
test: 'vendor'
}
}
Expand All @@ -44,15 +42,13 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-1" da
common: {
name: 'common',
chunks: 'initial',
enforce: true,
minChunks: 1
enforce: true
},
vendor: {
name: 'vendor',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: 'vendor'
}
}
Expand All @@ -75,7 +71,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-2" da
name: 'vendor',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: 'vendor'
}
}
Expand Down Expand Up @@ -117,7 +112,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-4" da
cacheGroups: {
main: {
name: 'main',
minChunks: 1,
test: 'main'
}
}
Expand All @@ -140,7 +134,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-5" da
name: 'main',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: 'main'
}
}
Expand All @@ -167,7 +160,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6a" d
name: 'main',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -197,7 +189,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6b" d
name: 'main',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -231,7 +222,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6c" d
name: 'main',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -265,7 +255,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-6d" d
name: 'main',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: module => {
if (module.getChunks().some(chunk => chunk.name === 'main'))
Expand Down Expand Up @@ -304,7 +293,6 @@ exports[`commonsChunkPlugin transforms correctly using "commonsChunkPlugin-7" da
name: 'main',
chunks: 'initial',
enforce: true,
minChunks: 1,
test: 'main'
}
}
Expand Down
20 changes: 13 additions & 7 deletions packages/migrate/commonsChunkPlugin/commonsChunkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ export default function(j: IJSCodeshift, ast: INode): INode {
);

Object.keys(cacheGroup).forEach((chunkName: string): void => {
const chunkProps: INode[] = [
let chunkProps: INode[] = [
createProperty(j, "name", chunkName),
];

const chunkPropsToAdd = [];
const chunkPropsToAdd = cacheGroup[chunkName];

if (!isAsyncChunk) {
chunkProps.push(...commonCacheGroupsProps);
}

if (chunkCount > 0) {
if (chunkCount > 1) {
chunkProps.push(
j.property(
"init",
Expand All @@ -184,12 +184,18 @@ export default function(j: IJSCodeshift, ast: INode): INode {
);
}

const chunkPropsKeys = chunkPropsToAdd.some((prop) => prop.key.name === "test" && prop.value.type === "Literal");

if (chunkPropsKeys) {
chunkProps = chunkProps.filter((prop) => prop.key.name !== "minChunks");
}

if (
cacheGroup[chunkName] &&
Array.isArray(cacheGroup[chunkName]) &&
cacheGroup[chunkName].length > 0
chunkPropsToAdd &&
Array.isArray(chunkPropsToAdd) &&
chunkPropsToAdd.length > 0
) {
chunkProps.push(...cacheGroup[chunkName]);
chunkProps.push(...chunkPropsToAdd);
}

cacheGroups.push(
Expand Down

0 comments on commit e404f3b

Please sign in to comment.