diff --git a/client/webpack.config.desktop.js b/client/webpack.config.desktop.js index 5cd86ff9f340b..f6b11f140e52b 100644 --- a/client/webpack.config.desktop.js +++ b/client/webpack.config.desktop.js @@ -83,6 +83,7 @@ module.exports = { ], resolve: { extensions: [ '.json', '.js', '.jsx', '.ts', '.tsx' ], + mainFields: [ 'calypso:src', 'module', 'main' ], modules: [ __dirname, 'node_modules' ], alias: { config: 'server/config', diff --git a/client/webpack.config.js b/client/webpack.config.js index 5903cff178498..38d4576b21944 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -256,6 +256,7 @@ const webpackConfig = { }, resolve: { extensions: [ '.json', '.js', '.jsx', '.ts', '.tsx' ], + mainFields: [ 'browser', 'calypso:src', 'module', 'main' ], modules: [ __dirname, 'node_modules' ], alias: Object.assign( { diff --git a/client/webpack.config.node.js b/client/webpack.config.node.js index 2e6206851d7ef..f429f56511e0f 100644 --- a/client/webpack.config.node.js +++ b/client/webpack.config.node.js @@ -59,6 +59,7 @@ function getMonorepoPackages() { * * @returns {Array} list of externals */ + function getExternals() { return [ // Don't bundle any node_modules, both to avoid a massive bundle, and problems @@ -144,6 +145,7 @@ const webpackConfig = { }, resolve: { extensions: [ '.json', '.js', '.jsx', '.ts', '.tsx' ], + mainFields: [ 'calypso:src', 'module', 'main' ], modules: [ __dirname, path.join( __dirname, 'extensions' ), 'node_modules' ], alias: { 'calypso/config': 'server/config', diff --git a/packages/babel-plugin-transform-wpcalypso-async/jest.config.js b/packages/babel-plugin-transform-wpcalypso-async/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/babel-plugin-transform-wpcalypso-async/jest.config.js +++ b/packages/babel-plugin-transform-wpcalypso-async/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/calypso-analytics/jest.config.js b/packages/calypso-analytics/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/calypso-analytics/jest.config.js +++ b/packages/calypso-analytics/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/calypso-build/webpack.config.js b/packages/calypso-build/webpack.config.js index d563544571c83..22df3672aa2b1 100644 --- a/packages/calypso-build/webpack.config.js +++ b/packages/calypso-build/webpack.config.js @@ -132,6 +132,7 @@ function getWebpackConfig( }, resolve: { extensions: [ '.json', '.js', '.jsx', '.ts', '.tsx' ], + mainFields: [ 'browser', 'calypso:src', 'module', 'main' ], modules: [ 'node_modules' ], }, node: false, diff --git a/packages/calypso-codemods/jest.config.js b/packages/calypso-codemods/jest.config.js index 38c6fc9e904a8..b704c656adf18 100644 --- a/packages/calypso-codemods/jest.config.js +++ b/packages/calypso-codemods/jest.config.js @@ -4,4 +4,5 @@ module.exports = { testMatch: [ '/tests/*/codemod.spec.js' ], setupFiles: [ '/setup-tests.js' ], cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/components/jest.config.js b/packages/components/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/components/jest.config.js +++ b/packages/components/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/composite-checkout/jest.config.js b/packages/composite-checkout/jest.config.js index 5c63fbf20b323..3ddfd2808d3de 100644 --- a/packages/composite-checkout/jest.config.js +++ b/packages/composite-checkout/jest.config.js @@ -4,4 +4,5 @@ module.exports = { testEnvironment: 'jsdom', globals: { window: { navigator: { userAgent: 'jest' } } }, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/composite-checkout/webpack.config.demo.js b/packages/composite-checkout/webpack.config.demo.js index 20c6cf230a5e6..e300562885ea2 100644 --- a/packages/composite-checkout/webpack.config.demo.js +++ b/packages/composite-checkout/webpack.config.demo.js @@ -18,7 +18,10 @@ module.exports = { }, ], }, - resolve: { extensions: [ '*', '.js', '.jsx' ] }, + resolve: { + extensions: [ '*', '.js', '.jsx' ], + mainFields: [ 'browser', 'calypso:src', 'module', 'main' ], + }, output: { path: path.resolve( __dirname, '/dist/' ), publicPath: '/dist/', diff --git a/packages/composite-checkout/webpack.config.js b/packages/composite-checkout/webpack.config.js index ac940d0c1a8c1..a0380fb3f2d45 100644 --- a/packages/composite-checkout/webpack.config.js +++ b/packages/composite-checkout/webpack.config.js @@ -27,7 +27,10 @@ module.exports = { }, ], }, - resolve: { extensions: [ '*', '.js', '.jsx' ] }, + resolve: { + extensions: [ '*', '.js', '.jsx' ], + mainFields: [ 'browser', 'calypso:src', 'module', 'main' ], + }, output: { path: path.resolve( __dirname, 'dist/' ), publicPath: '/dist/', diff --git a/packages/data-stores/jest.config.js b/packages/data-stores/jest.config.js index d48c7a1ad33be..e27cc661b4226 100644 --- a/packages/data-stores/jest.config.js +++ b/packages/data-stores/jest.config.js @@ -3,4 +3,5 @@ module.exports = { rootDir: __dirname, setupFiles: [ 'regenerator-runtime/runtime' ], cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/domain-picker/jest.config.js b/packages/domain-picker/jest.config.js index 03c0eea29f8a5..c930936b55413 100644 --- a/packages/domain-picker/jest.config.js +++ b/packages/domain-picker/jest.config.js @@ -6,4 +6,5 @@ module.exports = { globals: { __i18n_text_domain__: 'default', }, + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/effective-module-tree/jest.config.js b/packages/effective-module-tree/jest.config.js index 94c7b33cabe46..25a79abd199f6 100644 --- a/packages/effective-module-tree/jest.config.js +++ b/packages/effective-module-tree/jest.config.js @@ -4,4 +4,5 @@ module.exports = { // Node project, no need to transform anything transformIgnorePatterns: [ '/', '/node_modules/' ], cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/eslint-config-wpcalypso/jest.config.js b/packages/eslint-config-wpcalypso/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/eslint-config-wpcalypso/jest.config.js +++ b/packages/eslint-config-wpcalypso/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/eslint-plugin-wpcalypso/jest.config.js b/packages/eslint-plugin-wpcalypso/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/eslint-plugin-wpcalypso/jest.config.js +++ b/packages/eslint-plugin-wpcalypso/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/format-currency/jest.config.js b/packages/format-currency/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/format-currency/jest.config.js +++ b/packages/format-currency/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/format-currency/package.json b/packages/format-currency/package.json index 964775de3f9d6..c80afcb474294 100644 --- a/packages/format-currency/package.json +++ b/packages/format-currency/package.json @@ -4,6 +4,7 @@ "description": "JavaScript library for formatting currency", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "repository": { "type": "git", @@ -29,8 +30,8 @@ }, "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" }, "types": "types" } diff --git a/packages/i18n-calypso-cli/jest.config.js b/packages/i18n-calypso-cli/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/i18n-calypso-cli/jest.config.js +++ b/packages/i18n-calypso-cli/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/i18n-calypso/jest.config.js b/packages/i18n-calypso/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/i18n-calypso/jest.config.js +++ b/packages/i18n-calypso/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/i18n-calypso/package.json b/packages/i18n-calypso/package.json index 15ff07b1ce196..933ddd4d87afa 100644 --- a/packages/i18n-calypso/package.json +++ b/packages/i18n-calypso/package.json @@ -4,6 +4,7 @@ "description": "i18n JavaScript library on top of Tannin originally used in Calypso", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "types": "types/index.d.ts", "sideEffects": false, "repository": { @@ -39,7 +40,7 @@ }, "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" } } diff --git a/packages/load-script/jest.config.js b/packages/load-script/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/load-script/jest.config.js +++ b/packages/load-script/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/load-script/package.json b/packages/load-script/package.json index 849a72548dfdb..6711f83dc82c1 100644 --- a/packages/load-script/package.json +++ b/packages/load-script/package.json @@ -4,6 +4,7 @@ "description": "Async Script Loader.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "keywords": [ "wordpress" ], @@ -28,7 +29,7 @@ }, "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" } } diff --git a/packages/media-library/jest.config.js b/packages/media-library/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/media-library/jest.config.js +++ b/packages/media-library/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/photon/jest.config.js b/packages/photon/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/photon/jest.config.js +++ b/packages/photon/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/photon/package.json b/packages/photon/package.json index 3ddfaef4b8770..ac519f6143111 100644 --- a/packages/photon/package.json +++ b/packages/photon/package.json @@ -4,6 +4,7 @@ "description": "JavaScript library for the WordPress.com Photon image manipulation service", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "repository": { "type": "git", @@ -38,7 +39,7 @@ }, "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" } } diff --git a/packages/popup-monitor/package.json b/packages/popup-monitor/package.json index 29687d84083c0..079af17f98614 100644 --- a/packages/popup-monitor/package.json +++ b/packages/popup-monitor/package.json @@ -4,6 +4,7 @@ "description": "Utility to facilitate the monitoring of a popup window close action.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "keywords": [ "wordpress", @@ -29,8 +30,8 @@ ], "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" }, "dependencies": { "lodash": "^4.17.15" diff --git a/packages/request-external-access/jest.config.js b/packages/request-external-access/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/request-external-access/jest.config.js +++ b/packages/request-external-access/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/request-external-access/package.json b/packages/request-external-access/package.json index 99f845d56ad99..a1ba9f7dbe4ed 100644 --- a/packages/request-external-access/package.json +++ b/packages/request-external-access/package.json @@ -4,6 +4,7 @@ "description": "Utility for requesting authorization of sharing services.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "keywords": [ "wordpress", @@ -30,8 +31,8 @@ ], "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" }, "dependencies": { "@automattic/popup-monitor": "^1.0.0" diff --git a/packages/social-previews/jest.config.js b/packages/social-previews/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/social-previews/jest.config.js +++ b/packages/social-previews/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/social-previews/package.json b/packages/social-previews/package.json index 08354a496f60f..8d9445a075b36 100644 --- a/packages/social-previews/package.json +++ b/packages/social-previews/package.json @@ -4,6 +4,7 @@ "description": "A suite of components to generate previews for a post for both social and search engines", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": [ "*.css", "*.scss" @@ -34,8 +35,8 @@ ], "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile && copy-assets" + "build": "transpile && copy-assets", + "prepack": "yarn run clean && yarn run build" }, "dependencies": { "@babel/runtime": "^7.11.1", diff --git a/packages/tree-select/jest.config.js b/packages/tree-select/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/tree-select/jest.config.js +++ b/packages/tree-select/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/tree-select/package.json b/packages/tree-select/package.json index 2b60da2306081..3a435ee99cc3c 100644 --- a/packages/tree-select/package.json +++ b/packages/tree-select/package.json @@ -11,6 +11,7 @@ "license": "GPL-2.0-or-later", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "repository": { "type": "git", @@ -29,7 +30,7 @@ ], "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" } } diff --git a/packages/viewport-react/jest.config.js b/packages/viewport-react/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/viewport-react/jest.config.js +++ b/packages/viewport-react/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/viewport-react/package.json b/packages/viewport-react/package.json index 391f3fa2fce8b..87a745534c773 100644 --- a/packages/viewport-react/package.json +++ b/packages/viewport-react/package.json @@ -4,6 +4,7 @@ "description": "React helpers for tracking viewport changes", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "repository": { "type": "git", @@ -30,8 +31,8 @@ }, "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" }, "publishConfig": { "access": "public" diff --git a/packages/viewport/jest.config.js b/packages/viewport/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/viewport/jest.config.js +++ b/packages/viewport/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/viewport/package.json b/packages/viewport/package.json index 5956fdbfe136a..f90bd3e844473 100644 --- a/packages/viewport/package.json +++ b/packages/viewport/package.json @@ -4,6 +4,7 @@ "description": "Vanilla helpers for tracking viewport changes", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "repository": { "type": "git", @@ -18,8 +19,8 @@ "homepage": "https://github.com/Automattic/wp-calypso/tree/HEAD/packages/viewport#readme", "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" }, "publishConfig": { "access": "public" diff --git a/packages/webpack-config-flag-plugin/jest.config.js b/packages/webpack-config-flag-plugin/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/webpack-config-flag-plugin/jest.config.js +++ b/packages/webpack-config-flag-plugin/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/webpack-inline-constant-exports-plugin/jest.config.js b/packages/webpack-inline-constant-exports-plugin/jest.config.js index b94a8c8661cfe..ec0a18b144880 100644 --- a/packages/webpack-inline-constant-exports-plugin/jest.config.js +++ b/packages/webpack-inline-constant-exports-plugin/jest.config.js @@ -2,4 +2,5 @@ module.exports = { preset: '@automattic/calypso-build', rootDir: __dirname, cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/wp-babel-makepot/jest.config.js b/packages/wp-babel-makepot/jest.config.js index 6e3acfa28109e..9d36966165669 100644 --- a/packages/wp-babel-makepot/jest.config.js +++ b/packages/wp-babel-makepot/jest.config.js @@ -2,4 +2,5 @@ module.exports = { rootDir: __dirname, testMatch: [ '/**/test/*.[jt]s?(x)', '!**/.eslintrc.*', '!**/examples/**' ], cacheDirectory: '/../../.cache/jest', + resolver: '/../../test/module-resolver.js', }; diff --git a/packages/wpcom-proxy-request/package.json b/packages/wpcom-proxy-request/package.json index a9874a9f3530f..7f96447d9886e 100644 --- a/packages/wpcom-proxy-request/package.json +++ b/packages/wpcom-proxy-request/package.json @@ -4,6 +4,7 @@ "description": "Proxied cookie-authenticated REST API requests to WordPress.com", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "sideEffects": false, "keywords": [ "browser", @@ -37,8 +38,8 @@ "types": "types", "scripts": { "clean": "npx rimraf dist", - "prepublish": "npm run clean", - "prepare": "transpile" + "build": "transpile", + "prepack": "yarn run clean && yarn run build" }, "dependencies": { "@babel/runtime": "^7.11.1", diff --git a/packages/wpcom.js/package.json b/packages/wpcom.js/package.json index 4d9fe4ecfae89..5854154679a82 100644 --- a/packages/wpcom.js/package.json +++ b/packages/wpcom.js/package.json @@ -4,12 +4,13 @@ "version": "6.0.0", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", + "calypso:src": "src/index.js", "author": "Automattic, Inc.", "private": true, "scripts": { "clean": "npx rimraf dist", - "prepublish": "yarn run clean", - "prepare": "run-s build:modules build:bundle", + "build": "run-s build:modules build:bundle", + "prepack": "yarn run clean && yarn run build", "build:modules": "transpile", "build:bundle": "webpack --display errors-only" }, @@ -34,7 +35,8 @@ ], "browser": { "./dist/cjs/lib/util/fs.js": "./dist/cjs/lib/util/fs-browser.js", - "./dist/esm/lib/util/fs.js": "./dist/esm/lib/util/fs-browser.js" + "./dist/esm/lib/util/fs.js": "./dist/esm/lib/util/fs-browser.js", + "./src/lib/util/fs.js": "./src/lib/util/fs-browser.js" }, "dependencies": { "@babel/runtime": "^7.11.1", diff --git a/test/client/jest.config.js b/test/client/jest.config.js index a051255bd26c1..3f2921dedb4ca 100644 --- a/test/client/jest.config.js +++ b/test/client/jest.config.js @@ -12,6 +12,7 @@ module.exports = { }, modulePaths: [ '/../test', '', '/extensions' ], rootDir: '../../client', + resolver: '../test/module-resolver.js', testEnvironment: 'node', transformIgnorePatterns: [ 'node_modules[\\/\\\\](?!flag-icon-css|redux-form|simple-html-tokenizer|draft-js|social-logos|gridicons|calypso)', diff --git a/test/integration/jest.config.js b/test/integration/jest.config.js index bf63aa86db00e..1666cfef2776d 100644 --- a/test/integration/jest.config.js +++ b/test/integration/jest.config.js @@ -5,6 +5,7 @@ module.exports = { modulePaths: [ '/test', '/client', '/client/extensions' ], rootDir: '../..', testEnvironment: 'node', + resolver: '/test/module-resolver.js', testMatch: [ '/bin/**/integration/*.[jt]s', '/client/**/integration/*.[jt]s', diff --git a/test/module-resolver.js b/test/module-resolver.js new file mode 100644 index 0000000000000..97d84c0d22db8 --- /dev/null +++ b/test/module-resolver.js @@ -0,0 +1,32 @@ +/** + * Implements a custom resolver that uses `pkg['calypso:src']` isntead of `pkg.main` for packages from the monorepo. + * + * Doc: https://jestjs.io/docs/en/configuration#resolver-string + * + * Jest will call this method with the package to be resolved. We'll call back the default resolver but passing + * an extra `packageFilter`. The default resolver will call `resolve` (https://www.npmjs.com/package/resolve). That + * library will read `package.json` from the requested module and pass it through `packageFilter` to pre-process it + * before trying to read the entrypoint. + * + * If the requested package _name_ is one of the packages we have under `./packages`, we tell the resolver to use `pkg['calypso:src']` + * to read the main file. + * + * @param {string} request The package being requested + * @param {*} options Options for the resolver + */ +module.exports = ( request, options ) => { + return options.defaultResolver( request, { + ...options, + packageFilter: ( pkg ) => { + //TODO: when Jest moves to resolver v2, this method will receive a second argument that points to the real package file (ie: no symlink) + //We can use it to determine if the package file is within the repo + if ( 'calypso:src' in pkg ) { + return { + ...pkg, + main: pkg[ 'calypso:src' ] || pkg.module, + }; + } + return pkg; + }, + } ); +}; diff --git a/test/server/jest.config.js b/test/server/jest.config.js index df1d95e59a5a6..0fc4889a67bff 100644 --- a/test/server/jest.config.js +++ b/test/server/jest.config.js @@ -4,6 +4,7 @@ module.exports = { rootDir: '../../client', roots: [ '/server' ], testEnvironment: 'node', + resolver: '/../test/module-resolver.js', transform: { '\\.[jt]sx?$': 'babel-jest', '\\.(gif|jpg|jpeg|png|svg|scss|sass|css)$': require.resolve(