From 1b7ce56de513fc78280b21464897f93da6dc64b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Mon, 8 Jan 2024 14:11:17 -0300 Subject: [PATCH 1/4] allow overriding certain config files --- .changeset/tricky-ties-hang.md | 5 +++++ packages/toolkit/utils/config.js | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .changeset/tricky-ties-hang.md diff --git a/.changeset/tricky-ties-hang.md b/.changeset/tricky-ties-hang.md new file mode 100644 index 00000000..4bb940e7 --- /dev/null +++ b/.changeset/tricky-ties-hang.md @@ -0,0 +1,5 @@ +--- +"10up-toolkit": patch +--- + +Fix: allow overriding buildfiles.config.js, filenames.config.js and paths.config.js as stated in README diff --git a/packages/toolkit/utils/config.js b/packages/toolkit/utils/config.js index 5c3f6029..54b7edab 100644 --- a/packages/toolkit/utils/config.js +++ b/packages/toolkit/utils/config.js @@ -109,10 +109,21 @@ const getDefaultConfig = () => { const analyze = hasArgInCLI('--analyze'); const include = hasArgInCLI('--include') ? getArgFromCLI('--include').split(',') : []; + const buildFilesPath = hasProjectFile('buildfiles.config.js') + ? fromProjectRoot('buildfiles.config.js') + : fromConfigRoot('buildfiles.config.js'); + + const filenamesPath = hasProjectFile('filenames.config.js') + ? fromProjectRoot('filenames.config.js') + : fromConfigRoot('filenames.config.js'); + const pathsPath = hasProjectFile('paths.config.js') + ? fromProjectRoot('paths.config.js') + : fromConfigRoot('paths.config.js'); + return { - entry: require(fromConfigRoot('buildfiles.config.js')), - filenames: require(fromConfigRoot('filenames.config.js')), - paths: require(fromConfigRoot('paths.config.js')), + entry: require(buildFilesPath), + filenames: require(filenamesPath), + paths: require(pathsPath), wordpress: wpMode !== 'false', devServer, devServerPort, From cd9ba32a0d018b5d86d80d429d57cfe5340b0b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Mon, 8 Jan 2024 14:20:43 -0300 Subject: [PATCH 2/4] tests --- .../.gitignore | 1 + .../__fixtures__/assets/css/admin-styles.css | 1 + .../__fixtures__/assets/css/frontend.css | 1 + .../__fixtures__/assets/js/admin.js | 3 + .../__fixtures__/assets/js/frontend.js | 13 ++++ .../includes/blocks/example/block.json | 43 +++++++++++++ .../includes/blocks/example/edit.js | 4 ++ .../includes/blocks/example/editor-styles.css | 1 + .../includes/blocks/example/index.js | 11 ++++ .../includes/blocks/example/save.js | 8 +++ .../filenames.config.js | 9 +++ .../package.json | 12 ++++ .../test.js | 63 +++++++++++++++++++ 13 files changed, 170 insertions(+) create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/.gitignore create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/admin-styles.css create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/frontend.css create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/admin.js create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/frontend.js create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/block.json create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/edit.js create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/editor-styles.css create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/index.js create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/save.js create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/filenames.config.js create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/package.json create mode 100644 packages/toolkit/__tests__/build-project-overriding-config-files/test.js diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/.gitignore b/packages/toolkit/__tests__/build-project-overriding-config-files/.gitignore new file mode 100644 index 00000000..0fa2fd4f --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/.gitignore @@ -0,0 +1 @@ +./dist diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/admin-styles.css b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/admin-styles.css new file mode 100644 index 00000000..46b115dc --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/admin-styles.css @@ -0,0 +1 @@ +.admin-class { color: blue; } diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/frontend.css b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/frontend.css new file mode 100644 index 00000000..635ea838 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/css/frontend.css @@ -0,0 +1 @@ +.test { color: red; } diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/admin.js b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/admin.js new file mode 100644 index 00000000..015d49eb --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/admin.js @@ -0,0 +1,3 @@ +import '../css/admin-styles.css'; + +export const admin = () => {}; diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/frontend.js b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/frontend.js new file mode 100644 index 00000000..09d85dd9 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/assets/js/frontend.js @@ -0,0 +1,13 @@ +/* eslint-disable*/ +import * as React from 'react'; +import ReactDOM from 'react-dom'; +import { useState } from 'react'; + +const App = () => { + const [state] = useState(1); + + return

This is a react app {state}

; +}; + +ReactDOM.render(, document.getElementById('root')); + diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/block.json b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/block.json new file mode 100644 index 00000000..24c94f14 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/block.json @@ -0,0 +1,43 @@ +{ + "title": "Example Block", + "description": "An Example Block", + "textdomain": "tenup-scaffold", + "name": "tenup/example", + "icon": "feedback", + "category": "tenup-scaffold-blocks", + "attributes": { + "title": { + "type": "string" + } + }, + "example": { + "attributes": { + "title": "Example Block" + } + }, + "supports": { + "align": false, + "alignWide": false, + "anchor": false, + "color": { + "gradients": false, + "background": false, + "text": false + }, + "customClassName": false, + "defaultStylePicker": false, + "typography": { + "fontSize": false, + "lineHeight": true + }, + "html": false, + "inserter": true, + "multiple": true, + "reusable": false, + "spacing": { + "padding": false + } + }, + "editorScript": "file:../../../../dist/editor.js", + "editorStyle": "file:../../../../dist/editor.css" +} diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/edit.js b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/edit.js new file mode 100644 index 00000000..c196244e --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/edit.js @@ -0,0 +1,4 @@ +import './editor-styles.css'; + +const ExampleBlockEdit = () => {}; +export default ExampleBlockEdit; diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/editor-styles.css b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/editor-styles.css new file mode 100644 index 00000000..67cbeaf4 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/editor-styles.css @@ -0,0 +1 @@ +/* Editor specific styles */ diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/index.js b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/index.js new file mode 100644 index 00000000..900006bb --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/index.js @@ -0,0 +1,11 @@ +/* eslint-disable */ +import { registerBlockType } from '@wordpress/blocks'; + +import edit from './edit'; +import save from './save'; +import block from './block.json'; + +registerBlockType(block, { + edit, + save, +}); diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/save.js b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/save.js new file mode 100644 index 00000000..daa1ee54 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/__fixtures__/includes/blocks/example/save.js @@ -0,0 +1,8 @@ +/** + * See https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/block-edit-save/#save + * + * @returns {null} Dynamic blocks do not save the HTML. + */ +const ExampleBlockSave = () => null; + +export default ExampleBlockSave; diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/filenames.config.js b/packages/toolkit/__tests__/build-project-overriding-config-files/filenames.config.js new file mode 100644 index 00000000..63e43da7 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/filenames.config.js @@ -0,0 +1,9 @@ +// filenames.config.js +module.exports = { + js: 'js/test/[name].js', + jsChunk: 'js/test/[name].[contenthash].chunk.js', + css: 'css/test/[name].css', + // changing where gutenberg blocks assets are stored. + block: 'js/test/blocks/[name]/editor.js', + blockCSS: 'css/test/blocks/[name]/editor.css', +}; diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/package.json b/packages/toolkit/__tests__/build-project-overriding-config-files/package.json new file mode 100644 index 00000000..cb435240 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/package.json @@ -0,0 +1,12 @@ +{ + "name": "test-build-project", + "10up-toolkit": { + "useBlockAssets": false, + "entry": { + "admin": "./__fixtures__/assets/js/admin.js", + "frontend": "./__fixtures__/assets/js/frontend.js", + "frontend-css": "./__fixtures__/assets/css/frontend.css", + "example-block": "./__fixtures__/includes/blocks/example/index.js" + } + } +} diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/test.js b/packages/toolkit/__tests__/build-project-overriding-config-files/test.js new file mode 100644 index 00000000..e5493ee8 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/test.js @@ -0,0 +1,63 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import spawn from 'cross-spawn'; +import fs from 'fs'; +import path from 'path'; + +describe('build a project (without useBlockAssets)', () => { + it('builds and compiles js and css', async () => { + spawn.sync('node', ['../../scripts/build'], { + cwd: __dirname, + }); + + expect(fs.existsSync(path.join(__dirname, 'dist', 'js', 'admin.js'))).toBeTruthy(); + expect(fs.existsSync(path.join(__dirname, 'dist', 'js', 'admin.asset.php'))).toBeTruthy(); + expect(fs.existsSync(path.join(__dirname, 'dist', 'js', 'frontend.js'))).toBeTruthy(); + expect( + fs.existsSync(path.join(__dirname, 'dist', 'js', 'frontend.asset.php')), + ).toBeTruthy(); + expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'frontend-css.css'))).toBeTruthy(); + expect( + fs.existsSync(path.join(__dirname, 'dist', 'css', 'frontend-css.asset.php')), + ).toBeTruthy(); + }); + + it('adds react dependencies to .asset.php files', () => { + spawn.sync('node', ['../../scripts/build'], { + cwd: __dirname, + }); + const frontendAssetPHP = fs + .readFileSync(path.join(__dirname, 'dist', 'js', 'frontend.asset.php')) + .toString(); + + expect(frontendAssetPHP).toMatch('wp-element'); + expect(frontendAssetPHP).toMatch('react-dom'); + expect(frontendAssetPHP).toMatch('react'); + }); + + it('extracts css imported in js files', () => { + spawn.sync('node', ['../../scripts/build'], { + cwd: __dirname, + }); + // chunk name for css imported in js matches the js entry point + expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'admin.css'))).toBeTruthy(); + + // this should not exist since it is not an entry point on its own + expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'admin-styles.css'))).toBeFalsy(); + }); + + it('builds blocks', () => { + // without useBlockAssets block.json should not be copied + expect( + fs.existsSync(path.join(__dirname, 'dist', 'blocks', 'example-block', 'block.json')), + ).toBeFalsy(); + + expect( + fs.existsSync(path.join(__dirname, 'dist', 'blocks', 'example-block', 'editor.js')), + ).toBeTruthy(); + + // css is being imported from editor.js so its name should be editor.css + expect( + fs.existsSync(path.join(__dirname, 'dist', 'blocks', 'example-block', 'editor.css')), + ).toBeTruthy(); + }); +}); From 5c1f867d09799b4bcc81bf2290a00eddfcc6ad03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Mon, 8 Jan 2024 14:53:09 -0300 Subject: [PATCH 3/4] add tests --- .../test.js | 50 +-- .../webpack-basic-config.js.snap | 218 +++++++++++- .../webpack-cli-arguments.js.snap | 327 +++++++++++++++++- .../webpack-fast-refresh.js.snap | 115 +++++- .../config/__tests__/webpack-basic-config.js | 4 +- .../config/__tests__/webpack-cli-arguments.js | 4 +- .../config/__tests__/webpack-fast-refresh.js | 2 +- packages/toolkit/jest.config.js | 8 +- 8 files changed, 649 insertions(+), 79 deletions(-) diff --git a/packages/toolkit/__tests__/build-project-overriding-config-files/test.js b/packages/toolkit/__tests__/build-project-overriding-config-files/test.js index e5493ee8..3f957738 100644 --- a/packages/toolkit/__tests__/build-project-overriding-config-files/test.js +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/test.js @@ -3,61 +3,27 @@ import spawn from 'cross-spawn'; import fs from 'fs'; import path from 'path'; -describe('build a project (without useBlockAssets)', () => { +describe('build a project (overriding config)', () => { it('builds and compiles js and css', async () => { spawn.sync('node', ['../../scripts/build'], { cwd: __dirname, }); - expect(fs.existsSync(path.join(__dirname, 'dist', 'js', 'admin.js'))).toBeTruthy(); - expect(fs.existsSync(path.join(__dirname, 'dist', 'js', 'admin.asset.php'))).toBeTruthy(); - expect(fs.existsSync(path.join(__dirname, 'dist', 'js', 'frontend.js'))).toBeTruthy(); + expect(fs.existsSync(path.join(__dirname, 'dist', 'js', 'test', 'admin.js'))).toBeTruthy(); expect( - fs.existsSync(path.join(__dirname, 'dist', 'js', 'frontend.asset.php')), + fs.existsSync(path.join(__dirname, 'dist', 'js', 'test', 'admin.asset.php')), ).toBeTruthy(); - expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'frontend-css.css'))).toBeTruthy(); expect( - fs.existsSync(path.join(__dirname, 'dist', 'css', 'frontend-css.asset.php')), + fs.existsSync(path.join(__dirname, 'dist', 'js', 'test', 'frontend.js')), ).toBeTruthy(); - }); - - it('adds react dependencies to .asset.php files', () => { - spawn.sync('node', ['../../scripts/build'], { - cwd: __dirname, - }); - const frontendAssetPHP = fs - .readFileSync(path.join(__dirname, 'dist', 'js', 'frontend.asset.php')) - .toString(); - - expect(frontendAssetPHP).toMatch('wp-element'); - expect(frontendAssetPHP).toMatch('react-dom'); - expect(frontendAssetPHP).toMatch('react'); - }); - - it('extracts css imported in js files', () => { - spawn.sync('node', ['../../scripts/build'], { - cwd: __dirname, - }); - // chunk name for css imported in js matches the js entry point - expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'admin.css'))).toBeTruthy(); - - // this should not exist since it is not an entry point on its own - expect(fs.existsSync(path.join(__dirname, 'dist', 'css', 'admin-styles.css'))).toBeFalsy(); - }); - - it('builds blocks', () => { - // without useBlockAssets block.json should not be copied expect( - fs.existsSync(path.join(__dirname, 'dist', 'blocks', 'example-block', 'block.json')), - ).toBeFalsy(); - + fs.existsSync(path.join(__dirname, 'dist', 'js', 'test', 'frontend.asset.php')), + ).toBeTruthy(); expect( - fs.existsSync(path.join(__dirname, 'dist', 'blocks', 'example-block', 'editor.js')), + fs.existsSync(path.join(__dirname, 'dist', 'css', 'test', 'frontend-css.css')), ).toBeTruthy(); - - // css is being imported from editor.js so its name should be editor.css expect( - fs.existsSync(path.join(__dirname, 'dist', 'blocks', 'example-block', 'editor.css')), + fs.existsSync(path.join(__dirname, 'dist', 'css', 'test', 'frontend-css.asset.php')), ).toBeTruthy(); }); }); diff --git a/packages/toolkit/config/__tests__/__snapshots__/webpack-basic-config.js.snap b/packages/toolkit/config/__tests__/__snapshots__/webpack-basic-config.js.snap index 62e956bc..a9a2eb0d 100644 --- a/packages/toolkit/config/__tests__/__snapshots__/webpack-basic-config.js.snap +++ b/packages/toolkit/config/__tests__/__snapshots__/webpack-basic-config.js.snap @@ -27,13 +27,106 @@ exports[`webpack.config.js properly detects user config files in package mode 1` { "loader": "/node_modules/babel-loader/lib/index.js", "options": { + "babelrc": false, "cacheDirectory": true, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": false, + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": false, + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", }, }, { "loader": "@linaria/webpack-loader", "options": { - "babelOptions": {}, + "babelOptions": { + "babelrc": false, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": false, + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": false, + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", + }, "extension": ".linaria.module.css", "overrideContext": "context => ({ ...context, @@ -71,7 +164,9 @@ exports[`webpack.config.js properly detects user config files in package mode 1` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, ], @@ -96,7 +191,9 @@ exports[`webpack.config.js properly detects user config files in package mode 1` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -128,7 +225,9 @@ exports[`webpack.config.js properly detects user config files in package mode 1` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -177,7 +276,7 @@ exports[`webpack.config.js properly detects user config files in package mode 1` "plugins": [ "ESLintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/eslint-webpack-plugin/.eslintcache","extensions":"js","emitError":true,"emitWarning":true,"failOnError":false,"resourceQueryExclude":[],"fix":false,"lintDirtyModulesOnly":true}", "MiniCssExtractPlugin: {"ignoreOrder":false,"runtime":true,"chunkFilename":"[id].css"}", - "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true}", + "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true,"configFile":"/config/stylelint.config.js"}", "WebpackBarPlugin: {"name":"webpack","color":"green","reporters":["basic"],"reporter":null}", "CleanExtractedDeps: {}", "WebpackRemoveEmptyScriptsPlugin: {"enabled":true,"verbose":false,"extensions":{},"ignore":[],"remove":{}}", @@ -233,13 +332,106 @@ exports[`webpack.config.js properly detects user config files in project mode 1` { "loader": "/node_modules/babel-loader/lib/index.js", "options": { + "babelrc": false, "cacheDirectory": true, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", }, }, { "loader": "@linaria/webpack-loader", "options": { - "babelOptions": {}, + "babelOptions": { + "babelrc": false, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", + }, "extension": ".linaria.module.css", "overrideContext": "context => ({ ...context, @@ -277,7 +469,9 @@ exports[`webpack.config.js properly detects user config files in project mode 1` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, ], @@ -302,7 +496,9 @@ exports[`webpack.config.js properly detects user config files in project mode 1` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -334,7 +530,9 @@ exports[`webpack.config.js properly detects user config files in project mode 1` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -390,7 +588,7 @@ exports[`webpack.config.js properly detects user config files in project mode 1` "ESLintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/eslint-webpack-plugin/.eslintcache","extensions":"js","emitError":true,"emitWarning":true,"failOnError":false,"resourceQueryExclude":[],"fix":false,"lintDirtyModulesOnly":true}", "MiniCssExtractPlugin: {"ignoreOrder":false,"runtime":true,"chunkFilename":"[id].css"}", "CopyPlugin: {}", - "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets2","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true}", + "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets2","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true,"configFile":"/config/stylelint.config.js"}", "WebpackBarPlugin: {"name":"webpack","color":"green","reporters":["basic"],"reporter":null}", "DependencyExtractionWebpackPlugin: {"combineAssets":false,"combinedOutputFile":null,"externalizedReport":false,"injectPolyfill":false,"outputFormat":"php","outputFilename":null,"useDefaults":true}", "CleanExtractedDeps: {}", diff --git a/packages/toolkit/config/__tests__/__snapshots__/webpack-cli-arguments.js.snap b/packages/toolkit/config/__tests__/__snapshots__/webpack-cli-arguments.js.snap index 607462f8..7aca43fd 100644 --- a/packages/toolkit/config/__tests__/__snapshots__/webpack-cli-arguments.js.snap +++ b/packages/toolkit/config/__tests__/__snapshots__/webpack-cli-arguments.js.snap @@ -335,13 +335,106 @@ exports[`webpack.config.js allows changing browsersync port 1`] = ` { "loader": "/node_modules/babel-loader/lib/index.js", "options": { + "babelrc": false, "cacheDirectory": true, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", }, }, { "loader": "@linaria/webpack-loader", "options": { - "babelOptions": {}, + "babelOptions": { + "babelrc": false, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", + }, "extension": ".linaria.module.css", "overrideContext": "context => ({ ...context, @@ -379,7 +472,9 @@ exports[`webpack.config.js allows changing browsersync port 1`] = ` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, ], @@ -404,7 +499,9 @@ exports[`webpack.config.js allows changing browsersync port 1`] = ` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -436,7 +533,9 @@ exports[`webpack.config.js allows changing browsersync port 1`] = ` { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -493,7 +592,7 @@ exports[`webpack.config.js allows changing browsersync port 1`] = ` "MiniCssExtractPlugin: {"ignoreOrder":false,"runtime":true,"chunkFilename":"[id].css"}", "CopyPlugin: {}", "NoBrowserSyncPlugin: {}", - "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true}", + "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true,"configFile":"/config/stylelint.config.js"}", "WebpackBarPlugin: {"name":"webpack","color":"green","reporters":["basic"],"reporter":null}", "DependencyExtractionWebpackPlugin: {"combineAssets":false,"combinedOutputFile":null,"externalizedReport":false,"injectPolyfill":false,"outputFormat":"php","outputFilename":null,"useDefaults":true}", "CleanExtractedDeps: {}", @@ -550,13 +649,106 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/babel-loader/lib/index.js", "options": { + "babelrc": false, "cacheDirectory": true, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", }, }, { "loader": "@linaria/webpack-loader", "options": { - "babelOptions": {}, + "babelOptions": { + "babelrc": false, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", + }, "extension": ".linaria.module.css", "overrideContext": "context => ({ ...context, @@ -594,7 +786,9 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, ], @@ -619,7 +813,9 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -651,7 +847,9 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -707,7 +905,7 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze "ESLintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/eslint-webpack-plugin/.eslintcache","extensions":"js","emitError":true,"emitWarning":true,"failOnError":false,"resourceQueryExclude":[],"fix":false,"lintDirtyModulesOnly":true}", "MiniCssExtractPlugin: {"ignoreOrder":false,"runtime":true,"chunkFilename":"[id].css"}", "CopyPlugin: {}", - "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true}", + "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true,"configFile":"/config/stylelint.config.js"}", "WebpackBarPlugin: {"name":"webpack","color":"green","reporters":["basic"],"reporter":null}", "DependencyExtractionWebpackPlugin: {"combineAssets":false,"combinedOutputFile":null,"externalizedReport":false,"injectPolyfill":false,"outputFormat":"php","outputFilename":null,"useDefaults":true}", "CleanExtractedDeps: {}", @@ -765,13 +963,106 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/babel-loader/lib/index.js", "options": { + "babelrc": false, "cacheDirectory": true, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", }, }, { "loader": "@linaria/webpack-loader", "options": { - "babelOptions": {}, + "babelOptions": { + "babelrc": false, + "configFile": false, + "plugins": [], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", + }, "extension": ".linaria.module.css", "overrideContext": "context => ({ ...context, @@ -809,7 +1100,9 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, ], @@ -834,7 +1127,9 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -866,7 +1161,9 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -922,7 +1219,7 @@ exports[`webpack.config.js includes webpack-bundle-analyzer when using --analyze "ESLintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/eslint-webpack-plugin/.eslintcache","extensions":"js","emitError":true,"emitWarning":true,"failOnError":false,"resourceQueryExclude":[],"fix":false,"lintDirtyModulesOnly":true}", "MiniCssExtractPlugin: {"ignoreOrder":false,"runtime":true,"chunkFilename":"[id].css"}", "CopyPlugin: {}", - "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true}", + "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true,"configFile":"/config/stylelint.config.js"}", "WebpackBarPlugin: {"name":"webpack","color":"green","reporters":["basic"],"reporter":null}", "DependencyExtractionWebpackPlugin: {"combineAssets":false,"combinedOutputFile":null,"externalizedReport":false,"injectPolyfill":false,"outputFormat":"php","outputFilename":null,"useDefaults":true}", "CleanExtractedDeps: {}", diff --git a/packages/toolkit/config/__tests__/__snapshots__/webpack-fast-refresh.js.snap b/packages/toolkit/config/__tests__/__snapshots__/webpack-fast-refresh.js.snap index 0d65afd8..67df7e90 100644 --- a/packages/toolkit/config/__tests__/__snapshots__/webpack-fast-refresh.js.snap +++ b/packages/toolkit/config/__tests__/__snapshots__/webpack-fast-refresh.js.snap @@ -48,13 +48,110 @@ exports[`webpack.config.js includes react-webpack-fast-refresh with the --hot op { "loader": "/node_modules/babel-loader/lib/index.js", "options": { + "babelrc": false, "cacheDirectory": true, + "configFile": false, + "plugins": [ + "/node_modules/react-refresh/babel.js", + ], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", }, }, { "loader": "@linaria/webpack-loader", "options": { - "babelOptions": {}, + "babelOptions": { + "babelrc": false, + "configFile": false, + "plugins": [ + "/node_modules/react-refresh/babel.js", + ], + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + [ + "@linaria", + { + "babelOptions": { + "babelrc": false, + "configFile": false, + "presets": [ + [ + "/packages/babel-preset-default/index.js", + { + "targets": [ + "> 1%", + "Firefox ESR", + "last 2 versions", + "not ie <= 11", + "not ie_mob <=11", + ], + "useBuiltIns": "usage", + "wordpress": true, + }, + ], + ], + "sourceType": "unambiguous", + }, + }, + ], + ], + "sourceType": "unambiguous", + }, "extension": ".linaria.module.css", "overrideContext": "context => ({ ...context, @@ -92,7 +189,9 @@ exports[`webpack.config.js includes react-webpack-fast-refresh with the --hot op { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, ], @@ -117,7 +216,9 @@ exports[`webpack.config.js includes react-webpack-fast-refresh with the --hot op { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -149,7 +250,9 @@ exports[`webpack.config.js includes react-webpack-fast-refresh with the --hot op { "loader": "/node_modules/postcss-loader/dist/cjs.js", "options": { - "postcssOptions": {}, + "postcssOptions": { + "config": "/config/postcss.config.js", + }, }, }, { @@ -202,11 +305,11 @@ exports[`webpack.config.js includes react-webpack-fast-refresh with the --hot op "maxEntrypointSize": 40960000, }, "plugins": [ - "HtmlWebpackPlugin: {"template":"public/index.html","templateContent":false,"filename":"index.html","publicPath":"auto","hash":false,"inject":"head","scriptLoading":"defer","compile":true,"favicon":false,"minify":"auto","cache":true,"showErrors":true,"chunks":"all","excludeChunks":[],"chunksSortMode":"auto","meta":{},"base":false,"title":"Webpack App","xhtml":false}", + "HtmlWebpackPlugin: {"template":"auto","templateContent":false,"filename":"index.html","publicPath":"auto","hash":false,"inject":"head","scriptLoading":"defer","compile":true,"favicon":false,"minify":"auto","cache":true,"showErrors":true,"chunks":"all","excludeChunks":[],"chunksSortMode":"auto","meta":{},"base":false,"title":"Webpack App","xhtml":false}", "ESLintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/eslint-webpack-plugin/.eslintcache","extensions":"js","emitError":true,"emitWarning":true,"failOnError":false,"resourceQueryExclude":[],"fix":false,"lintDirtyModulesOnly":true}", "MiniCssExtractPlugin: {"ignoreOrder":false,"runtime":true,"chunkFilename":"[id].css"}", "CopyPlugin: {}", - "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true}", + "StylelintWebpackPlugin: {"cache":true,"cacheLocation":"node_modules/.cache/stylelint-webpack-plugin/.stylelintcache","extensions":["css","scss","sass"],"emitError":true,"emitWarning":true,"failOnError":false,"context":"/assets","files":"**/*.(s(c|a)ss|css)","allowEmptyInput":true,"lintDirtyModulesOnly":true,"configFile":"/config/stylelint.config.js"}", "DependencyExtractionWebpackPlugin: {"combineAssets":false,"combinedOutputFile":null,"externalizedReport":false,"injectPolyfill":false,"outputFormat":"php","outputFilename":null,"useDefaults":true}", "CleanExtractedDeps: {}", "WebpackRemoveEmptyScriptsPlugin: {"enabled":true,"verbose":false,"extensions":{},"ignore":[],"remove":{}}", diff --git a/packages/toolkit/config/__tests__/webpack-basic-config.js b/packages/toolkit/config/__tests__/webpack-basic-config.js index ce3941a2..096e2018 100644 --- a/packages/toolkit/config/__tests__/webpack-basic-config.js +++ b/packages/toolkit/config/__tests__/webpack-basic-config.js @@ -136,7 +136,7 @@ describe('webpack.config.js', () => { }); it('properly detects user config files in package mode', () => { - hasProjectFileMock.mockReturnValue(true); + // hasProjectFileMock.mockReturnValue(true); getBuildFilesMock.mockReturnValue({}); getPackageMock.mockReturnValue({ name: '@10up/component-library', @@ -163,7 +163,7 @@ describe('webpack.config.js', () => { }); it('properly detects user config files in project mode', () => { - hasProjectFileMock.mockReturnValue(true); + // hasProjectFileMock.mockReturnValue(true); const entryBuildFiles = { entry1: 'entry1.js', entry2: 'entry2.js', diff --git a/packages/toolkit/config/__tests__/webpack-cli-arguments.js b/packages/toolkit/config/__tests__/webpack-cli-arguments.js index c43d5b51..029203ac 100644 --- a/packages/toolkit/config/__tests__/webpack-cli-arguments.js +++ b/packages/toolkit/config/__tests__/webpack-cli-arguments.js @@ -88,7 +88,7 @@ describe('webpack.config.js', () => { it('allows changing browsersync port', () => { process.argv.push('--port=3000'); - hasProjectFileMock.mockReturnValue(true); + // hasProjectFileMock.mockReturnValue(true); const entryBuildFiles = { entry1: 'entry1.js', }; @@ -111,7 +111,7 @@ describe('webpack.config.js', () => { it('includes webpack-bundle-analyzer when using --analyze', () => { process.argv.push('--analyze'); process.env.NODE_ENV = 'production'; - hasProjectFileMock.mockReturnValue(true); + // hasProjectFileMock.mockReturnValue(true); const entryBuildFiles = { entry1: 'entry1.js', }; diff --git a/packages/toolkit/config/__tests__/webpack-fast-refresh.js b/packages/toolkit/config/__tests__/webpack-fast-refresh.js index 4bd55dc1..055b2c02 100644 --- a/packages/toolkit/config/__tests__/webpack-fast-refresh.js +++ b/packages/toolkit/config/__tests__/webpack-fast-refresh.js @@ -40,7 +40,7 @@ describe('webpack.config.js', () => { it('includes react-webpack-fast-refresh with the --hot option', () => { process.argv.push('--hot'); process.env.NODE_ENV = 'development'; - hasProjectFileMock.mockReturnValue(true); + hasProjectFileMock.mockImplementation((file) => file === 'webpack.config.js'); const entryBuildFiles = { entry1: 'entry1.js', }; diff --git a/packages/toolkit/jest.config.js b/packages/toolkit/jest.config.js index 1824e168..ab8547be 100644 --- a/packages/toolkit/jest.config.js +++ b/packages/toolkit/jest.config.js @@ -1,7 +1,13 @@ module.exports = { testEnvironment: 'node', testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/test/*.[jt]s?(x)', '**/?(*.)test.[jt]s?(x)'], - testPathIgnorePatterns: ['/node_modules/', '/vendor/', '/__fixtures__/', '/dist/'], + testPathIgnorePatterns: [ + '/node_modules/', + '/vendor/', + '/__fixtures__/', + '/dist/', + '__tests__/build-project-overriding-config-files/filenames.config.js', + ], setupFilesAfterEnv: [require.resolve('@wordpress/jest-console')], resolver: './test-utils/resolver.js', snapshotSerializers: ['./test-utils/webpack-serializer.js'], From 39adb136c0430dde397d3f7ca7e80ae7a2739c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Mon, 8 Jan 2024 15:03:52 -0300 Subject: [PATCH 4/4] removing unnecessary code --- packages/toolkit/config/__tests__/webpack-basic-config.js | 2 -- packages/toolkit/config/__tests__/webpack-cli-arguments.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/packages/toolkit/config/__tests__/webpack-basic-config.js b/packages/toolkit/config/__tests__/webpack-basic-config.js index 096e2018..001393dd 100644 --- a/packages/toolkit/config/__tests__/webpack-basic-config.js +++ b/packages/toolkit/config/__tests__/webpack-basic-config.js @@ -136,7 +136,6 @@ describe('webpack.config.js', () => { }); it('properly detects user config files in package mode', () => { - // hasProjectFileMock.mockReturnValue(true); getBuildFilesMock.mockReturnValue({}); getPackageMock.mockReturnValue({ name: '@10up/component-library', @@ -163,7 +162,6 @@ describe('webpack.config.js', () => { }); it('properly detects user config files in project mode', () => { - // hasProjectFileMock.mockReturnValue(true); const entryBuildFiles = { entry1: 'entry1.js', entry2: 'entry2.js', diff --git a/packages/toolkit/config/__tests__/webpack-cli-arguments.js b/packages/toolkit/config/__tests__/webpack-cli-arguments.js index 029203ac..9a94d471 100644 --- a/packages/toolkit/config/__tests__/webpack-cli-arguments.js +++ b/packages/toolkit/config/__tests__/webpack-cli-arguments.js @@ -88,7 +88,6 @@ describe('webpack.config.js', () => { it('allows changing browsersync port', () => { process.argv.push('--port=3000'); - // hasProjectFileMock.mockReturnValue(true); const entryBuildFiles = { entry1: 'entry1.js', }; @@ -111,7 +110,6 @@ describe('webpack.config.js', () => { it('includes webpack-bundle-analyzer when using --analyze', () => { process.argv.push('--analyze'); process.env.NODE_ENV = 'production'; - // hasProjectFileMock.mockReturnValue(true); const entryBuildFiles = { entry1: 'entry1.js', };