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/__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..3f957738 --- /dev/null +++ b/packages/toolkit/__tests__/build-project-overriding-config-files/test.js @@ -0,0 +1,29 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import spawn from 'cross-spawn'; +import fs from 'fs'; +import path from 'path'; + +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', 'test', 'admin.js'))).toBeTruthy(); + expect( + fs.existsSync(path.join(__dirname, 'dist', 'js', 'test', 'admin.asset.php')), + ).toBeTruthy(); + expect( + fs.existsSync(path.join(__dirname, 'dist', 'js', 'test', 'frontend.js')), + ).toBeTruthy(); + expect( + fs.existsSync(path.join(__dirname, 'dist', 'js', 'test', 'frontend.asset.php')), + ).toBeTruthy(); + expect( + fs.existsSync(path.join(__dirname, 'dist', 'css', 'test', 'frontend-css.css')), + ).toBeTruthy(); + expect( + 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..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 c43d5b51..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', }; 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'], 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,