Skip to content

Commit 6f19614

Browse files
committed
Update eslint config to newest format.
1 parent d3c029a commit 6f19614

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1586
-2056
lines changed

.eslintrc.js

Lines changed: 0 additions & 89 deletions
This file was deleted.

.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ locally, and be comfortable running commands from a terminal or command line int
88
The following tools will need to be installed.
99

1010
- [Composer](https://getcomposer.org/download/) v2 or later.
11-
- [Node.js](https://nodejs.org/en/download/) v14.15 or later with
12-
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) v7 or later.
11+
- [Node.js](https://nodejs.org/en/download/) v20.16.0 or later with
12+
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) v10 or later.
1313

1414
Once Node.js and npm are installed, run the following command from inside the plugin directory to install the required
1515
node packages:
@@ -20,11 +20,6 @@ Additionally, run the following command to install the required Composer package
2020

2121
composer install
2222

23-
You will also need a system-level copy of [gulp](https://gulpjs.com/docs/en/getting-started/quick-start) in order to
24-
run the build scripts:
25-
26-
npm install --global gulp-cli
27-
2823
## Building the plugin
2924

3025
Code Snippets is primarily written in PHP, which does not require any post-processing and should work out-of-the-box,
@@ -34,30 +29,25 @@ plugin can be loaded into WordPress.
3429

3530
In order to get things built from the source files, the following command can be used:
3631

37-
gulp
32+
npm run build
3833

39-
This will run the default `build` gulp task, which:
34+
This will run the basic Webpack configuration, which will:
4035

4136
1. Copies required vendor files from the `node_modules/` directory, such as CodeMirror and PrismJS theme files.
42-
2. Transforms the SCSS source files into browser-ready minified CSS code, including right-to-left files where appropriate.
37+
2. Transforms the SCSS source files into browser-ready minified CSS code, including right-to-left files where
38+
appropriate.
4339
3. Transforms the TypeScript source files into browser-ready minified JavaScript code, after checking with a linter.
4440

4541
The generated files will be located together under the `dist/` directory, where they are loaded from by WordPress.
4642

47-
This task can also be run with `gulp build`. More information on the specific tasks available, such as only performing
48-
a single step out of those listed above, can be found by inspecting [`gulpfile.babel.ts`](gulpfile.babel.ts) or running
49-
the following command:
50-
51-
gulp --tasks
52-
5343
## Building while developing
5444

5545
If you are actively editing the included TypeScript or SCSS sources and wish to see your changes reflected more quickly
5646
than running the entire build script, there is an alternative command available that will monitor the source files
57-
for changes and run only the necessary tasks when changes are detected. This can be begun by running the following
47+
for changes and run only the necessary tasks when changes are detected. This can be begun by running the following
5848
command:
5949

60-
gulp watch
50+
npm run watch
6151

6252
## Preparing for release
6353

@@ -68,7 +58,7 @@ In order to simplify things and reduce the file size of the distributed plugin p
6858
generating these distribution files separately from the plugin source. Running the following command will commence this
6959
process:
7060

71-
gulp bundle
61+
npm run bundle
7262

7363
This command will regenerate all processed files and copy those to be distributed to the `bundle/` directory, where they
7464
can be copied directly into a Subversion repository or similar for distribution.

config/webpack-css.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ export const cssWebpackConfig: Configuration = {
4545
use: [
4646
MiniCssExtractPlugin.loader,
4747
{
48-
loader: "css-loader",
48+
loader: 'css-loader',
4949
options: {
5050
sourceMap: true,
5151
importLoaders: 2
5252
}
5353
},
5454
{
55-
loader: "postcss-loader",
55+
loader: 'postcss-loader',
5656
options: {
5757
postcssOptions
5858
}
5959
},
6060
{
61-
loader: "sass-loader",
61+
loader: 'sass-loader',
6262
options: {
6363
implementation: libsass,
6464
sourceMap: true
@@ -71,14 +71,14 @@ export const cssWebpackConfig: Configuration = {
7171
use: [
7272
MiniCssExtractPlugin.loader,
7373
{
74-
loader: "css-loader",
74+
loader: 'css-loader',
7575
options: {
7676
sourceMap: false,
7777
importLoaders: 1
7878
}
7979
},
8080
{
81-
loader: "postcss-loader",
81+
loader: 'postcss-loader',
8282
options: {
8383
postcssOptions: {
8484
plugins: [cssnano()]
@@ -93,15 +93,15 @@ export const cssWebpackConfig: Configuration = {
9393
new RemoveEmptyScriptsPlugin(),
9494
new MiniCssExtractPlugin({
9595
filename: ({ chunk }) =>
96-
chunk ?
96+
chunk?.name ?
9797
`${chunk.name}.css`
9898
.replace(/^codemirror-theme-/, 'editor-themes/')
9999
.replace(/-style\.css$/, '.css') :
100100
'[name].css'
101101
}),
102102
new WebpackRTLPlugin({
103-
test: /^(edit|manage)\.css$/,
104-
filename: [/(\.css)/i, '-rtl$1']
103+
test: /^(?<filename>edit|manage)\.css$/,
104+
filename: [/(?<ext>\.css)/i, '-rtl$1']
105105
})
106106
]
107107
}

config/webpack-js.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
1-
import path from 'path'
21
import { DefinePlugin, Configuration } from 'webpack'
2+
import { join, resolve } from 'path'
33
import ESLintPlugin from 'eslint-webpack-plugin'
44
import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts'
5+
import { toCamelCase } from '../js/utils/text'
6+
import { dependencies } from '../package.json'
57

68
const SOURCE_DIR = './js'
79

10+
const babelConfig = {
11+
presets: [
12+
'@babel/preset-env',
13+
'@wordpress/babel-preset-default'
14+
],
15+
plugins: [
16+
['prismjs', {
17+
languages: ['php', 'php-extras'],
18+
plugins: ['line-highlight', 'line-numbers']
19+
}]
20+
]
21+
}
22+
823
export const jsWebpackConfig: Configuration = {
924
entry: {
10-
manage: `${SOURCE_DIR}/manage/index.ts`,
11-
edit: {
12-
import: `${SOURCE_DIR}/Edit/index.tsx`,
13-
dependOn: 'editor'
14-
},
15-
settings: {
16-
import: `${SOURCE_DIR}/settings/index.ts`,
17-
dependOn: 'editor'
18-
},
25+
edit: { import: `${SOURCE_DIR}/edit.tsx`, dependOn: 'editor' },
26+
editor: `${SOURCE_DIR}/editor.ts`,
27+
manage: `${SOURCE_DIR}/manage.ts`,
1928
mce: `${SOURCE_DIR}/mce.ts`,
2029
prism: `${SOURCE_DIR}/prism.ts`,
21-
editor: `${SOURCE_DIR}/editor.ts`
30+
settings: { import: `${SOURCE_DIR}/settings.ts`, dependOn: 'editor' }
2231
},
2332
output: {
24-
path: path.join(path.resolve(__dirname), '..', 'dist'),
33+
path: join(resolve(__dirname), '..', 'dist'),
2534
filename: '[name].js',
2635
clean: true
2736
},
@@ -33,19 +42,17 @@ export const jsWebpackConfig: Configuration = {
3342
'tinymce': 'tinymce',
3443
'codemirror': ['wp', 'CodeMirror'],
3544
...Object.fromEntries(
36-
['api-fetch', 'block-editor', 'blocks', 'components', 'data', 'i18n', 'server-side-render']
37-
.map(p => [
38-
`@wordpress/${p}`,
39-
['wp', p.replace(/-(?<letter>[a-z])/g, (_, letter) => letter.toUpperCase())]
45+
Object.keys(dependencies)
46+
.filter(name => name.startsWith('@wordpress/'))
47+
.map(packageName => [
48+
packageName,
49+
['wp', toCamelCase(packageName.replace('@wordpress/', ''))]
4050
])
4151
)
4252
},
4353
resolve: {
44-
modules: [path.resolve(__dirname, '..', 'node_modules')],
45-
extensions: ['.ts', '.tsx', '.js', '.json'],
46-
alias: {
47-
'php-parser': path.resolve(__dirname, '../node_modules/php-parser/src/index.js')
48-
}
54+
modules: [resolve(__dirname, '..', 'node_modules')],
55+
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
4956
},
5057
module: {
5158
rules: [
@@ -54,18 +61,7 @@ export const jsWebpackConfig: Configuration = {
5461
exclude: /node_modules/,
5562
use: {
5663
loader: 'babel-loader',
57-
options: {
58-
presets: [
59-
'@babel/preset-env',
60-
'@wordpress/babel-preset-default'
61-
],
62-
plugins: [
63-
['prismjs', {
64-
languages: ['php', 'php-extras'],
65-
plugins: ['line-highlight', 'line-numbers']
66-
}]
67-
]
68-
}
64+
options: babelConfig
6965
}
7066
}
7167
]

0 commit comments

Comments
 (0)