Skip to content
Open
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
25 changes: 6 additions & 19 deletions dev-apps/js-cloud-server/cloudflare-worker/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
const { composePlugins, withNx } = require('@nx/webpack')
const {
configureExternals,
configureNodeResolve,
} = require('../../../webpack-utils')

module.exports = composePlugins(withNx(), (config, { options }) => {
config.node = {
__dirname: true,
}
if (!config.resolve) {
config.resolve = {}
}
// Disable browser field resolution for node targets
config.resolve.mainFields = ['main', 'module']
config.resolve.conditionNames = ['node', 'require', 'import']
// Configure externals - webpack externals function
if (options.external && Array.isArray(options.external)) {
config.externals = config.externals || []
const externalArray = Array.isArray(config.externals)
? config.externals
: [config.externals]
config.externals = [
...externalArray,
...options.external.map((pkg) => ({
[pkg]: `commonjs ${pkg}`,
})),
]
}
configureNodeResolve(config)

Copilot AI Jan 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cloudflare-worker config now includes extensionAlias configuration (.js': ['.ts', '.js']) through configureNodeResolve, but the original implementation did not have this setting. This adds new module resolution behavior that wasn't previously present. While the PR description states the cloudflare-worker builds successfully, adding extension aliasing could potentially affect runtime behavior in the Cloudflare Worker environment. Verify that this addition is intentional and doesn't cause issues with how the worker resolves TypeScript imports at runtime.

Copilot uses AI. Check for mistakes.
configureExternals(config, options)
return config
})
28 changes: 6 additions & 22 deletions dev-apps/nodejs-cloud/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
const { composePlugins, withNx } = require('@nx/webpack')
const {
configureExternals,
configureNodeResolve,
} = require('../../webpack-utils')

module.exports = composePlugins(withNx(), (config, { options }) => {
if (!config.resolve) {
config.resolve = {}
}
config.resolve.extensionAlias = {
'.js': ['.ts', '.js'],
}
// Disable browser field resolution for node targets
config.resolve.mainFields = ['main', 'module']
config.resolve.conditionNames = ['node', 'require', 'import']
// Configure externals - webpack externals function
if (options.external && Array.isArray(options.external)) {
config.externals = config.externals || []
const externalArray = Array.isArray(config.externals)
? config.externals
: [config.externals]
config.externals = [
...externalArray,
...options.external.map((pkg) => ({
[pkg]: `commonjs ${pkg}`,
})),
]
}
configureNodeResolve(config)
configureExternals(config, options)
return config
})
36 changes: 7 additions & 29 deletions dev-apps/nodejs-local/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { composePlugins, withNx } = require('@nx/webpack')
const path = require('path')
const {
configureExternals,
configureNodeResolve,
} = require('../../webpack-utils')

module.exports = composePlugins(withNx(), (config, { options }) => {
// turn on __dirname replacement so that the WASM file can be referenced by the assemblyscript lib
Expand All @@ -24,15 +28,7 @@ module.exports = composePlugins(withNx(), (config, { options }) => {
}),
)

if (!config.resolve) {
config.resolve = {}
}
config.resolve.extensionAlias = {
'.js': ['.ts', '.js'],
}
// Disable browser field resolution for node targets
config.resolve.mainFields = ['main', 'module']
config.resolve.conditionNames = ['node', 'require', 'import']
configureNodeResolve(config)
// Don't use browser field for resolution
if (!config.resolve.aliasFields) {
config.resolve.aliasFields = []
Expand All @@ -41,25 +37,7 @@ module.exports = composePlugins(withNx(), (config, { options }) => {
if (!config.resolve.modules) {
config.resolve.modules = ['node_modules']
}
// Configure externals - use array format which is simpler and more reliable
if (options.external && Array.isArray(options.external)) {
// Convert to object format for webpack externals
const externalsObj = {}
options.external.forEach((pkg) => {
externalsObj[pkg] = `commonjs ${pkg}`
})
const originalExternals = config.externals
if (originalExternals) {
if (Array.isArray(originalExternals)) {
config.externals = [...originalExternals, externalsObj]
} else if (typeof originalExternals === 'object') {
config.externals = { ...originalExternals, ...externalsObj }
} else {
config.externals = [originalExternals, externalsObj]
}
} else {
config.externals = externalsObj
}
}

configureExternals(config, options)
return config
})
29 changes: 7 additions & 22 deletions dev-apps/openfeature-nodejs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { composePlugins, withNx } = require('@nx/webpack')
const path = require('path')
const webpack = require('webpack')
const {
configureExternals,
configureNodeResolve,
} = require('../../webpack-utils')

module.exports = composePlugins(withNx(), (config, { options }) => {
// turn on __dirname replacement so that the WASM file can be referenced by the assemblyscript lib
Expand All @@ -24,15 +28,7 @@ module.exports = composePlugins(withNx(), (config, { options }) => {
}),
)

if (!config.resolve) {
config.resolve = {}
}
config.resolve.extensionAlias = {
'.js': ['.ts', '.js'],
}
// Disable browser field resolution for node targets
config.resolve.mainFields = ['main', 'module']
config.resolve.conditionNames = ['node', 'require', 'import']
configureNodeResolve(config)
// Don't use browser field for resolution
if (!config.resolve.aliasFields) {
config.resolve.aliasFields = []
Expand All @@ -41,18 +37,7 @@ module.exports = composePlugins(withNx(), (config, { options }) => {
if (!config.resolve.modules) {
config.resolve.modules = ['node_modules']
}
// Configure externals - webpack externals function
if (options.external && Array.isArray(options.external)) {
config.externals = config.externals || []
const externalArray = Array.isArray(config.externals)
? config.externals
: [config.externals]
config.externals = [
...externalArray,
...options.external.map((pkg) => ({
[pkg]: `commonjs ${pkg}`,
})),
]
}

configureExternals(config, options)
return config
})
51 changes: 51 additions & 0 deletions webpack-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Shared webpack configuration utilities
*/

/**
* Merges external packages from Nx options into webpack config.externals.
* Handles array, object, and function formats for existing externals.

Copilot AI Jan 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc comment claims the function "Handles array, object, and function formats for existing externals," but the implementation only handles array format and a generic fallback. When originalExternals is an object (like { pkg: 'commonjs pkg' }), it's treated as the fallback case and wrapped in an array, which works but isn't explicitly object-aware. The comment should be updated to accurately reflect the implementation, or the implementation should include explicit object handling as the original nodejs-local code did.

Suggested change
* Handles array, object, and function formats for existing externals.
* Supports existing externals configured as arrays or other Webpack-supported types.

Copilot uses AI. Check for mistakes.
*
* @param {Object} config - Webpack configuration object
* @param {Object} options - Nx build options
*/
function configureExternals(config, options) {
if (!options.external || !Array.isArray(options.external)) {
return
}

const externalPackages = options.external.map((pkg) => ({
[pkg]: `commonjs ${pkg}`,
}))

const originalExternals = config.externals
if (!originalExternals) {
config.externals = externalPackages
} else if (Array.isArray(originalExternals)) {
config.externals = [...originalExternals, ...externalPackages]
} else {
config.externals = [originalExternals, ...externalPackages]
Comment on lines +17 to +27

Copilot AI Jan 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configureExternals function now creates an array of separate objects for external packages (e.g., [{pkg1: 'commonjs pkg1'}, {pkg2: 'commonjs pkg2'}]), which differs from the nodejs-local original implementation that merged all packages into a single object (e.g., {pkg1: 'commonjs pkg1', pkg2: 'commonjs pkg2'}). While both formats are valid for webpack externals, this changes the behavior for nodejs-local. Consider consolidating the external packages into a single object to maintain backward compatibility with the original nodejs-local implementation, or verify that all builds work correctly with the new format.

Suggested change
const externalPackages = options.external.map((pkg) => ({
[pkg]: `commonjs ${pkg}`,
}))
const originalExternals = config.externals
if (!originalExternals) {
config.externals = externalPackages
} else if (Array.isArray(originalExternals)) {
config.externals = [...originalExternals, ...externalPackages]
} else {
config.externals = [originalExternals, ...externalPackages]
const externalPackages = options.external.reduce((acc, pkg) => {
acc[pkg] = `commonjs ${pkg}`
return acc
}, {})
const originalExternals = config.externals
if (!originalExternals) {
config.externals = externalPackages
} else if (Array.isArray(originalExternals)) {
config.externals = [...originalExternals, externalPackages]
} else {
config.externals = [originalExternals, externalPackages]

Copilot uses AI. Check for mistakes.
}
}

/**
* Configures resolve settings for Node.js targets.
* Sets up extension aliases, main fields, and condition names.
*
* @param {Object} config - Webpack configuration object
*/
function configureNodeResolve(config) {
if (!config.resolve) {
config.resolve = {}
}
config.resolve.extensionAlias = {
'.js': ['.ts', '.js'],
}
config.resolve.mainFields = ['main', 'module']
config.resolve.conditionNames = ['node', 'require', 'import']
}

module.exports = {
configureExternals,
configureNodeResolve,
}