Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/strange-beans-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Add consitent plugin naming and error message formatting
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ interface ChunksToHermesBytecodePluginConfig {
* @category Webpack Plugin
*/
export class ChunksToHermesBytecodePlugin implements RspackPluginInstance {
private readonly name = 'ChunksToHermesBytecodePlugin';

constructor(private config: ChunksToHermesBytecodePluginConfig) {}

apply(compiler: Compiler) {
const logger = compiler.getInfrastructureLogger(this.name);
const logger = compiler.getInfrastructureLogger(
'RepackChunksToHermesBytecodePlugin'
);

if (!this.config.enabled) {
logger.debug('Skipping hermes compilation');
Expand All @@ -101,7 +101,7 @@ export class ChunksToHermesBytecodePlugin implements RspackPluginInstance {
this.config.hermesCLIPath || getHermesCLIPath(reactNativePath);

compiler.hooks.assetEmitted.tapPromise(
{ name: this.name, stage: 10 },
{ name: 'RepackChunksToHermesBytecodePlugin', stage: 10 },
async (file, { outputPath }) => {
const shouldTransformAsset =
compiler.webpack.ModuleFilenameHelpers.matchObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const composeSourceMaps = async ({
} catch (error) {
const message = (error as Error).toString();
throw new Error(
`ChunksToHermesBytecodePlugin: Failed to compose source maps. Reason:\n${message})`
`[RepackChunksToHermesBytecodePlugin] Failed to compose source maps. Reason:\n${message})`
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const getHermesCLIPath = (reactNativePath: string): string => {

if (!osBin) {
throw new Error(
'ChunksToHermesBytecodePlugin: OS not recognized. Please set hermesCLIPath to the path of a working Hermes compiler.'
'[RepackChunksToHermesBytecodePlugin] OS not recognized. ' +
'Please set hermesCLIPath to the path of a working Hermes compiler.'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const transformBundleToHermesBytecode = async ({
} catch (error) {
const message = (error as Error).toString();
throw new Error(
`ChunksToHermesBytecodePlugin: Failed to transform bundle ${bundlePath}. Reason:\n${message})`
`[RepackChunksToHermesBytecodePlugin] Failed to transform bundle ${bundlePath}. Reason:\n${message})`
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ export class CodeSigningPlugin implements RspackPluginInstance {
* @param compiler Webpack compiler instance.
*/
apply(compiler: Compiler) {
const pluginName = CodeSigningPlugin.name;
const logger = compiler.getInfrastructureLogger(pluginName);
const logger = compiler.getInfrastructureLogger('RepackCodeSigningPlugin');

if (this.config.enabled === false) {
return;
}

if (typeof compiler.options.output.filename === 'function') {
throw new Error(
'CodeSigningPlugin does not support dynamic output filename. Please use static filename instead.'
'[RepackCodeSigningPlugin] Dynamic output filename is not supported. Please use static filename instead.'
);
}
/**
Expand All @@ -76,14 +75,14 @@ export class CodeSigningPlugin implements RspackPluginInstance {
? this.config.excludeChunks
: [this.config.excludeChunks as RegExp];

compiler.hooks.emit.tap(pluginName, (compilation) => {
compiler.hooks.emit.tap('RepackCodeSigningPlugin', (compilation) => {
compilation.chunks.forEach((chunk) => {
chunk.files.forEach((file) => this.chunkFilenames.add(file));
});
});

compiler.hooks.assetEmitted.tapPromise(
{ name: pluginName, stage: 20 },
{ name: 'RepackCodeSigningPlugin', stage: 20 },
async (file, { outputPath, content, compilation }) => {
const mainBundleName = compilation.outputOptions.filename as string;
if (!this.shouldSignFile(file, mainBundleName, excludedChunks)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/repack/src/plugins/CodegenPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class CodegenPlugin implements RspackPluginInstance {
});
} catch {
throw new Error(
"CodegenPlugin requires '@react-native/babel-preset' to be present in your project. " +
"[RepackCodegenPlugin] Codegen requires '@react-native/babel-preset' to be present in your project. " +
'Did you forget to install it?'
);
}
Expand All @@ -77,7 +77,7 @@ export class CodegenPlugin implements RspackPluginInstance {
});
} catch {
throw new Error(
"CodegenPlugin requires 'babel-plugin-syntax-hermes-parser' to be present in your project. " +
"[RepackCodegenPlugin] Codegen requires 'babel-plugin-syntax-hermes-parser' to be present in your project. " +
'Did you forget to install it?'
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/repack/src/plugins/DevelopmentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class DevelopmentPlugin implements RspackPluginInstance {
];

compiler.hooks.entryOption.tap(
{ name: 'DevelopmentPlugin' },
{ name: 'RepackDevelopmentPlugin' },
(_, entryNormalized) => {
// combine entries for all declared and MF entrypoints
const entrypoints = [
Expand All @@ -184,7 +184,7 @@ export class DevelopmentPlugin implements RspackPluginInstance {
// similar to how dynamic entries work. This means the federation entry is added after our development entries.
// We need to reorder dependencies to ensure federation entry is placed before development entries.
compiler.hooks.make.tap(
{ name: 'DevelopmentPlugin', stage: 1000 },
{ name: 'RepackDevelopmentPlugin', stage: 1000 },
(compilation) => {
for (const entry of compilation.entries.values()) {
moveElementBefore(entry.dependencies, {
Expand Down
6 changes: 3 additions & 3 deletions packages/repack/src/plugins/LoggerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class LoggerPlugin implements RspackPluginInstance {
}

compiler.hooks.infrastructureLog.tap(
'LoggerPlugin',
'RepackLoggerPlugin',
(issuer, type, args) => {
const entry = this.createEntry(issuer, type, args);
if (entry) {
Expand All @@ -149,7 +149,7 @@ export class LoggerPlugin implements RspackPluginInstance {
}
);

compiler.hooks.thisCompilation.tap('LoggerPlugin', (compilation) => {
compiler.hooks.thisCompilation.tap('RepackLoggerPlugin', (compilation) => {
compilation.hooks.log.intercept({
call: (issuer, { time, type, args }) => {
const entry = this.createEntry(issuer, type, args, time);
Expand All @@ -160,7 +160,7 @@ export class LoggerPlugin implements RspackPluginInstance {
});
});

compiler.hooks.done.tap('LoggerPlugin', (stats) => {
compiler.hooks.done.tap('RepackLoggerPlugin', (stats) => {
if (this.config.devServerEnabled) {
const { time, errors, warnings } = stats.toJson({
all: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/repack/src/plugins/ManifestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class ManifestPlugin implements RspackPluginInstance {
* @param compiler Webpack compiler instance.
*/
apply(compiler: Compiler) {
compiler.hooks.compilation.tap('ManifestPlugin', (compilation) => {
compilation.hooks.afterProcessAssets.tap('ManifestPlugin', () => {
compiler.hooks.compilation.tap('RepackManifestPlugin', (compilation) => {
compilation.hooks.afterProcessAssets.tap('RepackManifestPlugin', () => {
for (const chunk of compilation.chunks) {
const manifest = {
id: chunk.id,
Expand Down
6 changes: 4 additions & 2 deletions packages/repack/src/plugins/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ export class ModuleFederationPlugin implements RspackPluginInstance {
}

apply(compiler: Compiler) {
const logger = compiler.getInfrastructureLogger('ModuleFederationPlugin');
const logger = compiler.getInfrastructureLogger(
'RepackModuleFederationPlugin'
);

compiler.hooks.beforeCompile.tap('ModuleFederationPlugin', () => {
compiler.hooks.beforeCompile.tap('RepackModuleFederationPlugin', () => {
logger.warn(
'Notice: ModuleFederationPlugin currently points to ModuleFederationPluginV1. ' +
'Re.Pack 5 introduced ModuleFederationPluginV2, which addresses many previous limitations. ' +
Expand Down
4 changes: 2 additions & 2 deletions packages/repack/src/plugins/ModuleFederationPluginV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ModuleFederationPluginV2 implements RspackPluginInstance {
if (!name) return;
if (!isIdentifier(name)) {
const error = new Error(
`[ModuleFederationPlugin] The container's name: '${name}' must be a valid JavaScript identifier. ` +
`[RepackModuleFederationPlugin] The container's name: '${name}' must be a valid JavaScript identifier. ` +
'Please correct it to proceed. For more information, see: https://developer.mozilla.org/en-US/docs/Glossary/Identifier'
);
// remove the stack trace to make the error more readable
Expand All @@ -130,7 +130,7 @@ export class ModuleFederationPluginV2 implements RspackPluginInstance {
require.resolve('@module-federation/enhanced', { paths: [context] });
} catch {
throw new Error(
"[ModuleFederationPlugin] Dependency '@module-federation/enhanced' is required, but not found in your project. " +
"[RepackModuleFederationPlugin] Dependency '@module-federation/enhanced' is required, but not found in your project. " +
'Did you forget to install it?'
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/repack/src/plugins/NativeEntryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class NativeEntryPlugin implements RspackPluginInstance {
];

compiler.hooks.entryOption.tap(
{ name: 'NativeEntryPlugin', before: 'DevelopmentPlugin' },
{ name: 'RepackNativeEntryPlugin', before: 'RepackDevelopmentPlugin' },
(_, entry) => {
if (typeof entry === 'function') {
throw new Error(
Expand All @@ -87,7 +87,7 @@ export class NativeEntryPlugin implements RspackPluginInstance {
// similar to how dynamic entries work. This means the federation entry is added after our native entries.
// We need to reorder dependencies to ensure federation entry is placed before native entries.
compiler.hooks.make.tap(
{ name: 'NativeEntryPlugin', stage: 1000 },
{ name: 'RepackNativeEntryPlugin', stage: 1000 },
(compilation) => {
for (const entry of compilation.entries.values()) {
moveElementBefore(entry.dependencies, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('ModuleFederationPlugin', () => {
expect(() => {
new ModuleFederationPluginV2({ name }).apply(mockCompiler);
}).toThrow(
`[ModuleFederationPlugin] The container's name: '${name}' must be a valid JavaScript identifier. ` +
`[RepackModuleFederationPlugin] The container's name: '${name}' must be a valid JavaScript identifier. ` +
'Please correct it to proceed.'
);
});
Expand Down