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/late-squids-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": major
---

Deprecate `getPublicPath` utility. The `getPublicPath` function is now a no-op marked as deprecated, while public path configuration is handled automatically under the hood.
1 change: 0 additions & 1 deletion apps/tester-app/rspack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default (env) => {
path: path.join(context, 'build/generated', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'tester-app',
},
optimization: {
Expand Down
1 change: 0 additions & 1 deletion apps/tester-app/webpack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default (env) => {
path: path.join(dirname, 'build/generated', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'tester-app',
},
optimization: {
Expand Down
1 change: 0 additions & 1 deletion apps/tester-federation-v2/configs/rspack.host-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'host-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MF2Tester-HostApp',
},
optimization: {
Expand Down
2 changes: 0 additions & 2 deletions apps/tester-federation-v2/configs/rspack.mini-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'mini-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MF2Tester-MiniApp',
},
optimization: {
Expand Down Expand Up @@ -98,7 +97,6 @@ export default (env) => {
'./MiniAppNavigator': './src/mini/navigation/MainNavigator',
},
dts: false,
getPublicPath: `return "http://localhost:8082/${platform}/"`,
shared: {
react: {
singleton: true,
Expand Down
1 change: 0 additions & 1 deletion apps/tester-federation-v2/configs/webpack.host-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'host-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MF2Tester-HostApp',
},
optimization: {
Expand Down
2 changes: 0 additions & 2 deletions apps/tester-federation-v2/configs/webpack.mini-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'mini-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MF2Tester-MiniApp',
},
optimization: {
Expand Down Expand Up @@ -79,7 +78,6 @@ export default (env) => {
'./MiniAppNavigator': './src/mini/navigation/MainNavigator',
},
dts: false,
getPublicPath: `return "http://localhost:8082/${platform}/"`,
shared: {
react: {
singleton: true,
Expand Down
1 change: 0 additions & 1 deletion apps/tester-federation/configs/rspack.host-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'host-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MFTester-HostApp',
},
optimization: {
Expand Down
1 change: 0 additions & 1 deletion apps/tester-federation/configs/rspack.mini-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'mini-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MFTester-MiniApp',
},
optimization: {
Expand Down
1 change: 0 additions & 1 deletion apps/tester-federation/configs/webpack.host-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'host-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MFTester-HostApp',
},
optimization: {
Expand Down
1 change: 0 additions & 1 deletion apps/tester-federation/configs/webpack.mini-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default (env) => {
path: path.join(dirname, 'build', 'mini-app', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
uniqueName: 'MFTester-MiniApp',
},
optimization: {
Expand Down
7 changes: 7 additions & 0 deletions packages/repack/src/commands/common/config/getRepackConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function getRepackConfig() {
return {
output: {
publicPath: 'noop:///',
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getCliOverrides } from './getCliOverrides.js';
import { getCommandConfig } from './getCommandConfig.js';
import { getConfigFilePath } from './getConfigFilePath.js';
import { getEnvOptions } from './getEnvOptions.js';
import { getRepackConfig } from './getRepackConfig.js';
import { loadProjectConfig } from './loadProjectConfig.js';
import { normalizeConfig } from './normalizeConfig.js';

Expand Down Expand Up @@ -40,6 +41,9 @@ export async function makeCompilerConfig<C extends ConfigurationObject>(
// get defaults for use with specific commands
const commandConfig = getCommandConfig(command);

// get defaults that will be applied on top of built-in ones (Rspack/webpack)
const repackConfig = getRepackConfig();

// load the project config
const rawConfig = await loadProjectConfig<C>(configPath);

Expand All @@ -52,7 +56,7 @@ export async function makeCompilerConfig<C extends ConfigurationObject>(

// merge in reverse order to create final configs
const configs = normalizedConfigs.map((config) =>
merge([commandConfig, config, cliConfigOverrides])
merge([repackConfig, commandConfig, config, cliConfigOverrides])
);

return configs as C[];
Expand Down
5 changes: 5 additions & 0 deletions packages/repack/src/commands/common/config/normalizeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export async function normalizeConfig<C extends ConfigurationObject>(
/* normalize compiler name to be equal to platform */
configObject.name = env.platform;

/* unset public path if it's using the deprecated `getPublicPath` function */
if (configObject.output?.publicPath === 'DEPRECATED_GET_PUBLIC_PATH') {
configObject.output.publicPath = undefined;
}

/* return the normalized config object */
return configObject;
}
3 changes: 2 additions & 1 deletion packages/repack/src/commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ type ConfigKeys =
| 'mode'
| 'devServer'
| 'entry'
| 'optimization';
| 'optimization'
| 'output';

export type ConfigurationObject = Partial<Record<ConfigKeys, any>>;

Expand Down
16 changes: 12 additions & 4 deletions packages/repack/src/plugins/DevelopmentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,25 @@ export class DevelopmentPlugin implements RspackPluginInstance {
const [majorVersion, minorVersion, patchVersion] =
reactNativePackageJson.version.split('-')[0].split('.');

const host = this.config.devServer.host || 'localhost';
const port = this.config.devServer.port;
const protocol = this.config.devServer.https ? 'https' : 'http';
const platform = this.config.platform;

new compiler.webpack.DefinePlugin({
__PLATFORM__: JSON.stringify(this.config.platform),
__PUBLIC_PROTOCOL__: this.config.devServer.https ? '"https"' : '"http"',
__PUBLIC_HOST__: JSON.stringify(this.config.devServer.host),
__PUBLIC_PORT__: Number(this.config.devServer.port),
__PUBLIC_PROTOCOL__: JSON.stringify(protocol),
__PUBLIC_HOST__: JSON.stringify(host),
__PUBLIC_PORT__: Number(port),
__REACT_NATIVE_MAJOR_VERSION__: Number(majorVersion),
__REACT_NATIVE_MINOR_VERSION__: Number(minorVersion),
__REACT_NATIVE_PATCH_VERSION__: Number(patchVersion),
}).apply(compiler);

// Enforce output filenames in development mode
// set public path for development with dev server
compiler.options.output.publicPath = `${protocol}://${host}:${port}/${platform}/`;

// enforce output filenames in development mode
compiler.options.output.filename = (pathData) =>
pathData.chunk?.name === 'main' ? 'index.bundle' : '[name].bundle';
compiler.options.output.chunkFilename = '[name].chunk.bundle';
Expand Down
51 changes: 9 additions & 42 deletions packages/repack/src/utils/getPublicPath.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
import type { DevServerOptions } from '../types.js';

/** {@link getPublicPath} options. */
export interface GetPublicPathOptions {
/** Target application platform. */
platform: string;

/** Development server configuration options. */
devServer?: DevServerOptions;
}

/**
* Get Webpack's public path.
*
* @param options Options object.
* @returns Value for Webpack's `output.publicPath` option.
*
* @category Webpack util
*
* @example Usage in Webpack config:
* ```ts
* import * as Repack from '@callstack/repack';
*
* export default (env) => {
* const {
* platform,
* devServer = undefined,
* } = env;
* @deprecated Since Re.Pack v5.0.0.
*
* return {
* output: {
* publicPath: Repack.getPublicPath({ platform, devServer }),
* },
* };
* };
* ```
* You can safely remove this function call -
* the public path configuration is now automatically handled by Re.Pack with the same behavior.
*/
export function getPublicPath(options?: GetPublicPathOptions) {
if (options?.devServer) {
const { port, host, https } = options.devServer;
return `${https ? 'https' : 'http'}://${host || 'localhost'}:${port}/${
options.platform
}/`;
}
return 'noop:///';
export function getPublicPath() {
console.warn(
'[NOTICE] `getPublicPath` is deprecated since Re.Pack v5.0.0.\n' +
'You can safely remove this function call - the public path configuration is now automatically handled by Re.Pack with the same behavior.'
);
return 'DEPRECATED_GET_PUBLIC_PATH';
}
1 change: 0 additions & 1 deletion templates_v5/rspack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ module.exports = (env) => {
path: path.join(__dirname, 'build/generated', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
},
/** Configures optimization of the built bundle. */
optimization: {
Expand Down
1 change: 0 additions & 1 deletion templates_v5/rspack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export default (env) => {
path: path.join(dirname, 'build/generated', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
},
/** Configures optimization of the built bundle. */
optimization: {
Expand Down
1 change: 0 additions & 1 deletion templates_v5/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ module.exports = (env) => {
path: path.join(__dirname, 'build/generated', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
},
/**
* Configures optimization of the built bundle.
Expand Down
1 change: 0 additions & 1 deletion templates_v5/webpack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export default (env) => {
path: path.join(dirname, 'build/generated', platform),
filename: 'index.bundle',
chunkFilename: '[name].chunk.bundle',
publicPath: Repack.getPublicPath({ platform, devServer }),
},
/**
* Configures optimization of the built bundle.
Expand Down
1 change: 0 additions & 1 deletion website/src/5.x/api/utils/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"get-asset-extension-regexp",
"get-dirname",
"get-module-paths",
"get-public-path",
"get-resolve-options"
]
42 changes: 0 additions & 42 deletions website/src/5.x/api/utils/get-public-path.md

This file was deleted.