Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade latest [email protected] #227

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"terser-webpack-plugin": "^5.3.0",
"thread-loader": "^3.0.4",
"tslib": "^2.3.0",
"webpack": "^5.76.0",
"webpack": "^5.89.0",
"yargs": "^17.1.0"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/config/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ export const getWebpackConfig = ({
},
],
},
// @ts-expect-error
plugins: [
new MiniCssExtractPlugin({
filename: `[name].${CSS_FILE_EXT[target] ?? 'wxss'}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"typescript": "^4.3.5",
"utility-types": "^3.10.0",
"vscode-ripgrep": "^1.12.1",
"webpack": "^5.76.0"
"webpack": "^5.89.0"
},
"dependencies": {
"common-tags": "^2.0.0-alpha.1",
Expand Down
11 changes: 6 additions & 5 deletions packages/webpack-plugin/src/plugins/chunks/split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { AppConfig, GojiWebpackPluginRequiredOptions } from '../../types';
import { COMMON_CHUNK_NAME, NO_HOIST_TEMP_DIR } from '../../constants/paths';
import { normalizeCacheGroups } from '../../forked/splitChunksPlugin';
import { getChunkName } from '../../utils/chunkName';

type WebpackCacheGroups = NonUndefined<
Exclude<
Expand Down Expand Up @@ -63,15 +64,15 @@ const getNohoistModules = (
for (const module of modules) {
const chunks = chunkGraph.getModuleChunks(module);
const belongingSubPackages = findBelongingSubPackages(
chunks.map(chunk => chunk.name),
chunks.map(chunk => getChunkName(chunk)),
subPackageRoots,
);
const canNohoist = belongingSubPackages.size > 1 && !belongingSubPackages.has(MAIN_PACKAGE);
const forceNohoist = checkTest(options.test, module, chunks, false);
// should only nohoist if size between [2, N] where N is `nohoist.maxPackages`
if (canNohoist && (forceNohoist || belongingSubPackages.size <= options.maxPackages)) {
const hash = crypto.createHash('sha256');
for (const chunkName of chunks.map(chunk => chunk.name).sort()) {
for (const chunkName of chunks.map(chunk => getChunkName(chunk)).sort()) {
hash.update(chunkName);
}
const chunksHash = hash.digest('hex');
Expand All @@ -97,7 +98,7 @@ const getCacheGroups = (
name: COMMON_CHUNK_NAME,
priority: -5,
chunks: chunk => {
if (independents.find(item => isBelongsTo(chunk.name, item.root ?? ''))) {
if (independents.find(item => isBelongsTo(getChunkName(chunk), item.root ?? ''))) {
return false;
}

Expand All @@ -121,9 +122,9 @@ const getCacheGroups = (

return context.chunkGraph
.getModuleChunks(module)
.every(item => isBelongsTo(item.name, subPackage));
.every(item => isBelongsTo(getChunkName(item), subPackage));
},
chunks: chunk => isBelongsTo(chunk.name, subPackage),
chunks: chunk => isBelongsTo(getChunkName(chunk), subPackage),
};
}
if (options.enable) {
Expand Down
5 changes: 4 additions & 1 deletion packages/webpack-plugin/src/plugins/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../utils/loadConfig';
import { AppConfig } from '../types';
import { readPathsFromAppConfig } from '../utils/config';
import { getChunkName } from '../utils/chunkName';

/**
* resolve `app.json` to generate dynamic entries
Expand Down Expand Up @@ -68,7 +69,9 @@ export class GojiEntryWebpackPlugin extends GojiBasedWebpackPlugin {
// FIXME: remove the main entry which content is `app.json`
// is there any better way to avoid this chunk being generated ?
private removeMainEntry(compilation: webpack.Compilation) {
const mainChunk = [...compilation.chunks].find((chunk: webpack.Chunk) => chunk.name === 'main');
const mainChunk = [...compilation.chunks].find(
(chunk: webpack.Chunk) => getChunkName(chunk) === 'main',
);
if (!mainChunk) {
console.warn('main chunk not found');
return;
Expand Down
7 changes: 4 additions & 3 deletions packages/webpack-plugin/src/plugins/nohoist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import webpack, { ChunkGraph } from 'webpack';
import path from 'path';
import { GojiBasedWebpackPlugin } from './based';
import { NO_HOIST_PREFIX, NO_HOIST_TEMP_DIR } from '../constants/paths';
import { getChunkName } from '../utils/chunkName';

const isNohoistTempFile = (filePath: string) => filePath.startsWith(`${NO_HOIST_TEMP_DIR}/`);

Expand All @@ -21,10 +22,10 @@ export class GojiNohoistWebpackPlugin extends GojiBasedWebpackPlugin {
const { chunkGraph } = compilation;
// clean up useless chunks to prevent these temp files to be emitted
for (const chunk of chunks) {
if (!isNohoistTempFile(chunk.name)) {
if (!isNohoistTempFile(getChunkName(chunk))) {
continue;
}
const nohoistTempFileName = path.posix.basename(chunk.name);
const nohoistTempFileName = path.posix.basename(getChunkName(chunk));
const chunkGroups = chunk.groupsIterable;
const modules = chunkGraph.getChunkModules(chunk);
// move chunk into each chunkGroups(sub packages)
Expand All @@ -45,7 +46,7 @@ export class GojiNohoistWebpackPlugin extends GojiBasedWebpackPlugin {
}
// this line also clean up modules and groups
chunkGraph.disconnectChunk(chunk);
compilation.namedChunks.delete(chunk.name);
compilation.namedChunks.delete(getChunkName(chunk));
chunks.delete(chunk);
// TODO: remove in webpack 6
ChunkGraph.clearChunkGraphForChunk(chunk);
Expand Down
13 changes: 7 additions & 6 deletions packages/webpack-plugin/src/plugins/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import { GojiBasedWebpackPlugin } from './based';
import { safeUrlToRequest } from '../utils/path';
import { COMMON_CHUNK_NAME, RUNTIME_FILE_NAME } from '../constants/paths';
import { getChunkName } from '../utils/chunkName';

type RuntimePluginExt = '.js' | '.wxss';

Expand Down Expand Up @@ -64,11 +65,11 @@ export class GojiRuntimePlugin extends GojiBasedWebpackPlugin {
if (chunk === entryChunk) {
continue;
}
// assume output.filename is chunk.name here
const depentChunkName = chunk.name;
// assume output.filename is getChunkName(chunk) here
const dependentChunkName = getChunkName(chunk);
// uniq
if (!dependentChunkNames.includes(depentChunkName)) {
dependentChunkNames.push(chunk.name);
if (!dependentChunkNames.includes(dependentChunkName)) {
dependentChunkNames.push(dependentChunkName);
}
}
}
Expand Down Expand Up @@ -99,7 +100,7 @@ export class GojiRuntimePlugin extends GojiBasedWebpackPlugin {
const filteredDependentChunkNames = existedDependentChunkNames.filter(chunkName => {
if (chunkName === COMMON_CHUNK_NAME || chunkName === RUNTIME_FILE_NAME) {
// remove root common/runtime chunk for pages
if (entryChunk.name !== 'app') {
if (getChunkName(entryChunk) !== 'app') {
return false;
}
}
Expand All @@ -109,7 +110,7 @@ export class GojiRuntimePlugin extends GojiBasedWebpackPlugin {
meta.ext,
transformedExt,
filteredDependentChunkNames.map(chunkName =>
path.posix.relative(path.posix.dirname(entryChunk.name), chunkName),
path.posix.relative(path.posix.dirname(getChunkName(entryChunk)), chunkName),
),
);
compilation.assets[file] = new webpack.sources.ConcatSource(
Expand Down
7 changes: 4 additions & 3 deletions packages/webpack-plugin/src/plugins/singleton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import webpack, { Template } from 'webpack';
import { RUNTIME_FILE_NAME } from '../constants/paths';
import { GojiBasedWebpackPlugin } from './based';
import { getChunkName } from '../utils/chunkName';

const SOURCE_NAME = '';

Expand All @@ -22,7 +23,7 @@ export class GojiSingletonRuntimeWebpackPlugin extends GojiBasedWebpackPlugin {
webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).renderMain.tap(
'GojiSingletonRuntimeWebpackPlugin',
(source, context) => {
if (!context.chunk.name.endsWith('runtime')) {
if (!getChunkName(context.chunk).endsWith('runtime')) {
return source;
}
const { globalObject } = compilation.outputOptions;
Expand Down Expand Up @@ -56,7 +57,7 @@ export class GojiSingletonRuntimeWebpackPlugin extends GojiBasedWebpackPlugin {
webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).renderMain.tap(
'GojiFixIndependentRuntimePlugin',
(source, context) => {
if (!context.chunk.name.endsWith(RUNTIME_FILE_NAME)) {
if (!getChunkName(context.chunk).endsWith(RUNTIME_FILE_NAME)) {
return source;
}

Expand All @@ -67,7 +68,7 @@ export class GojiSingletonRuntimeWebpackPlugin extends GojiBasedWebpackPlugin {
new webpack.sources.PrefixSource(
'/*goji*/ ',
Template.asString([
`var _chunkPath = ${JSON.stringify(context.chunk.name)};`,
`var _chunkPath = ${JSON.stringify(getChunkName(context.chunk))};`,
`if (!${globalObject}.__gojiFixIndependentRuntime) {`,
Template.indent([
`Object.defineProperty(${globalObject}, '__gojiFixIndependentRuntime', {`,
Expand Down
8 changes: 8 additions & 0 deletions packages/webpack-plugin/src/utils/chunkName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import webpack from 'webpack';

export const getChunkName = (chunk: webpack.Chunk) => {
if (!chunk.name) {
throw new Error(`getChunkName(chunk) expected string but got ${typeof getChunkName(chunk)}`);
}
return chunk.name;
};
Loading
Loading