Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
fix(webpack): add missing webpack 4 polyfills
Browse files Browse the repository at this point in the history
* fix(webpack): add missing webpack 4 polyfills

* fix(webpack): update tests add snapshots
  • Loading branch information
dogpatch626 authored Mar 6, 2024
1 parent ba59a59 commit 1080885
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`webpack/module.client should generate full list of fall backs 1`] = `
Object {
"assert": "/mock/path/for/request/assert",
"buffer": "/mock/path/for/request/buffer",
"console": "/mock/path/for/request/console-browserify",
"constants": "/mock/path/for/request/constants-browserify",
"crypto": "/mock/path/for/request/crypto-browserify",
"domain": "/mock/path/for/request/domain-browser",
"events": "/mock/path/for/request/events",
"http": "/mock/path/for/request/stream-http",
"https": "/mock/path/for/request/https-browserify",
"os": "/mock/path/for/request/os-browserify/browser",
"path": "/mock/path/for/request/path-browserify",
"process": "/mock/path/for/request/process/browser",
"punycode": "/mock/path/for/request/punycode",
"querystring": "/mock/path/for/request/querystring-es3",
"stream": "/mock/path/for/request/stream-browserify",
"string_decoder": "/mock/path/for/request/string_decoder",
"sys": "/mock/path/for/request/util",
"timers": "/mock/path/for/request/timers-browserify",
"tty": "/mock/path/for/request/tty-browserify",
"url": "/mock/path/for/request/url",
"util": "/mock/path/for/request/util",
"vm": "/mock/path/for/request/vm-browserify",
"zlib": "/mock/path/for/request/browserify-zlib",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ jest.mock('@americanexpress/one-app-dev-bundler', () => ({ BUNDLE_TYPES: { BROWS

jest.mock('../../../utils/getConfigOptions', () => jest.fn(() => ({ purgecss: {} })));
jest.spyOn(process, 'cwd').mockImplementation(() => __dirname.split(`${path.sep}__tests__`)[0]);

jest.mock('../../../utils/getMetaUrl.mjs', () => () => 'metaUrlMock');

jest.mock('node:url', () => ({
fileURLToPath: jest.fn((url) => `/mock/path/for/url/${url}`),
}));

// Mock out create resolver to return a mock path for the webpack 4 pollyfill resolves.
jest.mock('../../../webpack/createResolver.js', () => jest.fn(() => jest.fn((request) => `/mock/path/for/request/${request}`)));

jest.mock('read-package-up', () => ({
readPackageUpSync: jest.fn(() => ({
packageJson: {
Expand All @@ -49,6 +51,12 @@ describe('webpack/module.client', () => {
expect(() => validateWebpackConfig(webpackConfig)).not.toThrow();
});

it('should generate full list of fall backs', async () => {
expect.assertions(2);
const webpackConfig = await configGenerator();
expect(() => validateWebpackConfig(webpackConfig)).not.toThrow();
expect(webpackConfig.resolve.fallback).toMatchSnapshot();
});
it('should provide the envName to babel', async () => {
expect.assertions(2);
const modernWebpackConfig = await configGenerator('modern');
Expand Down
22 changes: 22 additions & 0 deletions packages/one-app-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,51 @@
"@americanexpress/purgecss-loader": "4.0.0",
"@babel/core": "^7.22.20",
"ajv": "^8.12.0",
"assert": "^2.1.0",
"babel-loader": "^9.1.3",
"babel-preset-amex": "^4.0.1",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"chalk": "^5.3.0",
"console-browserify": "^1.2.0",
"constants-browserify": "^1.0.0",
"core-js-compat": "^3.32.2",
"crypto-browserify": "^3.12.0",
"css-loader": "6.8.1",
"domain-browser": "^5.7.0",
"enhanced-resolve": "^5.15.0",
"events": "^3.3.0",
"expose-loader": "^4.1.0",
"file-loader": "^6.2.0",
"folder-hash": "^4.0.4",
"glob": "^10.3.4",
"holocron-module-register-webpack-plugin": "^2.1.0",
"html-webpack-plugin": "^5.5.3",
"https-browserify": "^1.0.0",
"joi": "^17.10.2",
"loader-utils": "^3.2.1",
"lodash": "^4.17.21",
"mkdirp": "^3.0.1",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"punycode": "^2.3.1",
"querystring-es3": "^0.2.1",
"read-package-up": "^11.0.0",
"rimraf": "^5.0.1",
"source-map": "^0.7.4",
"ssri": "^10.0.5",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"string_decoder": "^1.3.0",
"style-loader": "^3.3.3",
"terser-webpack-plugin": "^5.3.9",
"timers-browserify": "^2.0.12",
"tty-browserify": "^0.0.1",
"url": "^0.11.3",
"url-loader": "^4.1.1",
"util": "^0.12.5",
"vm-browserify": "^1.1.2",
"webpack": "5.88.2",
"webpack-custom-chunk-id-plugin": "^1.0.3",
"webpack-merge": "^5.9.0",
Expand Down
28 changes: 25 additions & 3 deletions packages/one-app-bundler/webpack/module/webpack.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import getConfigOptions from '../../utils/getConfigOptions.js';
import {
babelLoader,
} from '../loaders/common.js';
import createResolver from '../createResolver.js';

const resolve = createResolver({ mainFields: ['browser', 'module', 'main'] });
const packageRoot = process.cwd();
const { packageJson } = readPackageUpSync();
const { version, name } = packageJson;
Expand All @@ -52,9 +54,29 @@ const webpackClient = async (babelEnv) => {
modules: [packageRoot, 'node_modules'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
fallback: {
fs: false,
module: false,
net: false,
assert: resolve('assert'),
buffer: resolve('buffer'),
console: resolve('console-browserify'),
constants: resolve('constants-browserify'),
crypto: resolve('crypto-browserify'),
domain: resolve('domain-browser'),
events: resolve('events'),
http: resolve('stream-http'),
https: resolve('https-browserify'),
os: resolve('os-browserify/browser'),
path: resolve('path-browserify'),
punycode: resolve('punycode'),
process: resolve('process/browser'),
querystring: resolve('querystring-es3'),
stream: resolve('stream-browserify'),
string_decoder: resolve('string_decoder'),
sys: resolve('util'),
timers: resolve('timers-browserify'),
tty: resolve('tty-browserify'),
url: resolve('url'),
util: resolve('util'),
vm: resolve('vm-browserify'),
zlib: resolve('browserify-zlib'),
},
},
performance: {
Expand Down
Loading

0 comments on commit 1080885

Please sign in to comment.