Skip to content

Commit 046f81c

Browse files
Merge remote-tracking branch 'upstream/main' into feat/es6-docs-update
# Conflicts: # src/content/plugins/commons-chunk-plugin.mdx
2 parents 53cba25 + 9706811 commit 046f81c

26 files changed

+808
-344
lines changed

.github/actions/webpack-persistent-cache/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ outputs:
99
runs:
1010
using: composite
1111
steps:
12-
- uses: actions/cache@v4
12+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
1313
id: build-webpack-persistent-cache
1414
with:
1515
path: node_modules/.cache

.github/workflows/dependency-review.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: 'Checkout Repository'
12-
uses: actions/checkout@v5
12+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1313
- name: 'Dependency Review'
14-
uses: actions/dependency-review-action@v4
14+
uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2

.github/workflows/deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
node-version: [lts/*]
1616
runs-on: ${{ matrix.os }}
1717
steps:
18-
- uses: actions/checkout@v5
18+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1919

2020
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v6
21+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
2222
with:
2323
node-version: ${{ matrix.node-version }}
2424
cache: yarn
@@ -35,7 +35,7 @@ jobs:
3535
- run: yarn lint:links
3636

3737
- name: Deploy
38-
uses: JamesIves/[email protected].3
38+
uses: JamesIves/github-pages-deploy-action@4a3abc783e1a24aeb44c16e869ad83caf6b4cc23 # v4.7.4
3939
with:
4040
token: ${{ secrets.GITHUB_TOKEN }}
4141
folder: dist

.github/workflows/testing.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
node-version: [lts/*]
1717
runs-on: ${{ matrix.os }}
1818
steps:
19-
- uses: actions/checkout@v5
19+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2020

2121
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v6
22+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
2323
with:
2424
node-version: ${{ matrix.node-version }}
2525
cache: yarn
@@ -35,10 +35,10 @@ jobs:
3535
node-version: [lts/*]
3636
runs-on: ${{ matrix.os }}
3737
steps:
38-
- uses: actions/checkout@v5
38+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
3939

4040
- name: Use Node.js ${{ matrix.node-version }}
41-
uses: actions/setup-node@v6
41+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
4242
with:
4343
node-version: ${{ matrix.node-version }}
4444
cache: yarn
@@ -55,10 +55,10 @@ jobs:
5555
node-version: [lts/*]
5656
runs-on: ${{ matrix.os }}
5757
steps:
58-
- uses: actions/checkout@v5
58+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5959

6060
- name: Use Node.js ${{ matrix.node-version }}
61-
uses: actions/setup-node@v6
61+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
6262
with:
6363
node-version: ${{ matrix.node-version }}
6464
cache: yarn
@@ -67,7 +67,7 @@ jobs:
6767
run: npm install -g mdx2vast
6868

6969
- name: Vale
70-
uses: errata-ai/[email protected]
70+
uses: errata-ai/vale-action@d89dee975228ae261d22c15adcd03578634d429c # v2.1.1
7171
with:
7272
files: src/content
7373
env:
@@ -81,10 +81,10 @@ jobs:
8181
node-version: [lts/*]
8282
runs-on: ${{ matrix.os }}
8383
steps:
84-
- uses: actions/checkout@v5
84+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
8585

8686
- name: Use Node.js ${{ matrix.node-version }}
87-
uses: actions/setup-node@v6
87+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
8888
with:
8989
node-version: ${{ matrix.node-version }}
9090
cache: yarn
@@ -95,7 +95,7 @@ jobs:
9595
uses: ./.github/actions/webpack-persistent-cache
9696

9797
- name: Cypress run
98-
uses: cypress-io/github-action@v6
98+
uses: cypress-io/github-action@7ef72e250a9e564efb4ed4c2433971ada4cc38b4 # v6.10.4
9999
with:
100100
browser: chrome
101101
config-file: cypress.config.js
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { useRef, useState } from 'react';
2+
import PropTypes from 'prop-types';
3+
import './CodeBlockWithCopy.scss';
4+
5+
export default function CodeBlockWithCopy({ children }) {
6+
const preRef = useRef(null);
7+
const [copyStatus, setCopyStatus] = useState('copy');
8+
9+
const handleCopy = async () => {
10+
if (!preRef.current) return;
11+
12+
const codeElement = preRef.current.querySelector('code');
13+
if (!codeElement) return;
14+
15+
const codeText = codeElement.textContent;
16+
let successfulCopy = false;
17+
18+
// Try modern API (navigator.clipboard) -> as document.execCommand() deprecated
19+
try {
20+
if (navigator.clipboard && window.isSecureContext) {
21+
await navigator.clipboard.writeText(codeText);
22+
successfulCopy = true;
23+
}
24+
} catch (err) {
25+
console.log(err);
26+
}
27+
28+
// If modern API failed, fall back to deprecated document.execCommand('copy')
29+
if (!successfulCopy) {
30+
const textarea = document.createElement('textarea');
31+
textarea.value = codeText;
32+
textarea.style.position = 'fixed';
33+
textarea.style.opacity = '0';
34+
35+
document.body.appendChild(textarea);
36+
textarea.select();
37+
38+
try {
39+
// This deprecated method is kept as a fallback for compatibility/iframe environments.
40+
successfulCopy = document.execCommand('copy');
41+
} catch (err) {
42+
successfulCopy = false;
43+
console.log(err);
44+
}
45+
46+
document.body.removeChild(textarea);
47+
}
48+
49+
setCopyStatus(successfulCopy ? 'copied' : 'error');
50+
setTimeout(() => setCopyStatus('copy'), 2000);
51+
};
52+
53+
return (
54+
<div className="code-block-wrapper">
55+
<button onClick={handleCopy} className={`copy-button ${copyStatus}`}>
56+
{copyStatus === 'copied'
57+
? 'Copied!'
58+
: copyStatus === 'error'
59+
? 'Error'
60+
: 'Copy'}
61+
</button>
62+
63+
<pre ref={preRef} className="code-block">
64+
{children}
65+
</pre>
66+
</div>
67+
);
68+
}
69+
70+
CodeBlockWithCopy.propTypes = {
71+
children: PropTypes.node.isRequired,
72+
};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.code-block-wrapper {
2+
position: relative;
3+
margin-bottom: 1.5rem;
4+
}
5+
6+
.code-block {
7+
background-color: #2d3748;
8+
color: #e2e8f0;
9+
padding: 1rem;
10+
padding-right: 3.5rem;
11+
border-radius: 0.5rem;
12+
overflow-x: auto;
13+
font-size: 0.875rem;
14+
line-height: 1.5;
15+
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
16+
17+
code {
18+
font-family: monospace;
19+
}
20+
}
21+
22+
.copy-button {
23+
position: absolute;
24+
top: 0.6rem;
25+
right: 0.5rem;
26+
z-index: 10;
27+
28+
padding: 0.4rem 0.7rem;
29+
border-radius: 0.35rem;
30+
31+
border: none;
32+
cursor: pointer;
33+
34+
font-size: 0.75rem;
35+
font-weight: 500;
36+
37+
/* Always visible */
38+
opacity: 1;
39+
40+
background-color: #175d96;
41+
color: #e2e8f0;
42+
43+
transition:
44+
background-color 0.2s,
45+
transform 0.1s;
46+
47+
&:hover {
48+
background-color: #2f85d0;
49+
}
50+
51+
/* Success */
52+
&.copied {
53+
background-color: #38a169;
54+
}
55+
&.copied:hover {
56+
background-color: #2f855a;
57+
}
58+
59+
/* Error */
60+
&.error {
61+
background-color: #e53e3e;
62+
}
63+
&.error:hover {
64+
background-color: #c53030;
65+
}
66+
67+
&:focus {
68+
outline: none;
69+
}
70+
71+
&:active {
72+
transform: scale(0.95);
73+
}
74+
}

src/content/concepts/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ Webpack supports all browsers that are [ES5-compliant](https://compat-table.gith
167167

168168
## Environment
169169

170-
Webpack 5 runs on Node.js version 10.13.0+.
170+
Webpack 5 requires Node.js version 10.13.0 or later.

src/content/concepts/output.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ contributors:
99
- EugeneHlushko
1010
---
1111

12+
import CodeBlockWithCopy from '../../components/CodeBlockWithCopy/CodeBlockWithCopy';
13+
1214
Configuring the `output` configuration options tells webpack how to write the compiled files to disk. Note that, while there can be multiple `entry` points, only one `output` configuration is specified.
1315

1416
## Usage

0 commit comments

Comments
 (0)