Skip to content

Commit ea7c490

Browse files
committedNov 3, 2023
Require Node.js 18
1 parent a243f4d commit ea7c490

File tree

4 files changed

+63
-78
lines changed

4 files changed

+63
-78
lines changed
 

‎.github/contributing.md

-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@
55
- Commit naming convention: `{ IssueID } { Issue Type (e.g. Enhancement, Bug, etc.) } short description`
66
- Run `npm test`
77
- Run `xo --fix` if you have any [coding style](https://github.com/sindresorhus/xo) issues. Most of them will be fixed for you.
8-
9-
10-

‎.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 20
1314
- 18
14-
- 16
1515
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions/setup-node@v3
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1818
with:
1919
node-version: ${{ matrix.node-version }}
2020
- run: npm install

‎index.js

+54-65
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import {Buffer} from 'node:buffer';
22
import path from 'node:path';
3-
import transformStream from 'easy-transform-stream';
43
import {vinylFile} from 'vinyl-file';
54
import revHash from 'rev-hash';
65
import {revPath} from 'rev-path';
76
import sortKeys from 'sort-keys';
87
import modifyFilename from 'modify-filename';
98
import Vinyl from 'vinyl';
10-
import PluginError from 'plugin-error';
9+
import {gulpPlugin} from 'gulp-plugin-extras';
1110

1211
function relativePath(base, filePath) {
13-
filePath = filePath.replace(/\\/g, '/');
14-
base = base.replace(/\\/g, '/');
12+
filePath = filePath.replaceAll('\\', '/');
13+
base = base.replaceAll('\\', '/');
1514

1615
if (!filePath.startsWith(base)) {
1716
return filePath;
@@ -55,20 +54,12 @@ const getManifestFile = async options => {
5554
}
5655
};
5756

58-
const plugin = () => {
57+
export default function gulpRev() {
5958
const sourcemaps = [];
6059
const pathMap = {};
6160

62-
return transformStream({objectMode: true}, file => {
63-
if (file.isNull()) {
64-
return file;
65-
}
66-
67-
if (file.isStream()) {
68-
throw new PluginError('gulp-rev', 'Streaming not supported');
69-
}
70-
71-
// This is a sourcemap, hold until the end
61+
return gulpPlugin('gulp-rev', file => {
62+
// This is a sourcemap, hold until the end.
7263
if (path.extname(file.path) === '.map') {
7364
sourcemaps.push(file);
7465
return;
@@ -79,40 +70,38 @@ const plugin = () => {
7970
pathMap[oldPath] = file.revHash;
8071

8172
return file;
82-
}, () => {
83-
const files = [];
84-
85-
for (const file of sourcemaps) {
86-
let reverseFilename;
87-
88-
// Attempt to parse the sourcemap's JSON to get the reverse filename
89-
try {
90-
reverseFilename = JSON.parse(file.contents.toString()).file;
91-
} catch {}
92-
93-
if (!reverseFilename) {
94-
reverseFilename = path.relative(path.dirname(file.path), path.basename(file.path, '.map'));
73+
}, {
74+
async * onFinish() {
75+
for (const file of sourcemaps) {
76+
let reverseFilename;
77+
78+
// Attempt to parse the sourcemap's JSON to get the reverse filename
79+
try {
80+
reverseFilename = JSON.parse(file.contents.toString()).file;
81+
} catch {}
82+
83+
if (!reverseFilename) {
84+
reverseFilename = path.relative(path.dirname(file.path), path.basename(file.path, '.map'));
85+
}
86+
87+
if (pathMap[reverseFilename]) {
88+
// Save the old path for later
89+
file.revOrigPath = file.path;
90+
file.revOrigBase = file.base;
91+
92+
const hash = pathMap[reverseFilename];
93+
file.path = revPath(file.path.replace(/\.map$/, ''), hash) + '.map';
94+
} else {
95+
transformFilename(file);
96+
}
97+
98+
yield file;
9599
}
96-
97-
if (pathMap[reverseFilename]) {
98-
// Save the old path for later
99-
file.revOrigPath = file.path;
100-
file.revOrigBase = file.base;
101-
102-
const hash = pathMap[reverseFilename];
103-
file.path = revPath(file.path.replace(/\.map$/, ''), hash) + '.map';
104-
} else {
105-
transformFilename(file);
106-
}
107-
108-
files.push(file);
109-
}
110-
111-
return files;
100+
},
112101
});
113-
};
102+
}
114103

115-
plugin.manifest = (path_, options) => {
104+
gulpRev.manifest = (path_, options) => {
116105
if (typeof path_ === 'string') {
117106
path_ = {path: path_};
118107
}
@@ -127,38 +116,38 @@ plugin.manifest = (path_, options) => {
127116

128117
let manifest = {};
129118

130-
return transformStream({objectMode: true}, file => {
119+
return gulpPlugin('gulp-rev', file => {
131120
// Ignore all non-rev'd files
132121
if (!file.path || !file.revOrigPath) {
133122
return;
134123
}
135124

136125
const revisionedFile = relativePath(path.resolve(file.cwd, file.base), path.resolve(file.cwd, file.path));
137-
const originalFile = path.join(path.dirname(revisionedFile), path.basename(file.revOrigPath)).replace(/\\/g, '/');
126+
const originalFile = path.join(path.dirname(revisionedFile), path.basename(file.revOrigPath)).replaceAll('\\', '/');
138127

139128
manifest[originalFile] = revisionedFile;
140-
}, async function * () {
141-
// No need to write a manifest file if there's nothing to manifest
142-
if (Object.keys(manifest).length === 0) {
143-
return;
144-
}
129+
}, {
130+
async * onFinish() {
131+
// No need to write a manifest file if there's nothing to manifest
132+
if (Object.keys(manifest).length === 0) {
133+
return;
134+
}
145135

146-
const manifestFile = await getManifestFile(options);
136+
const manifestFile = await getManifestFile(options);
147137

148-
if (options.merge && !manifestFile.isNull()) {
149-
let oldManifest = {};
138+
if (options.merge && !manifestFile.isNull()) {
139+
let oldManifest = {};
150140

151-
try {
152-
oldManifest = options.transformer.parse(manifestFile.contents.toString());
153-
} catch {}
141+
try {
142+
oldManifest = options.transformer.parse(manifestFile.contents.toString());
143+
} catch {}
154144

155-
manifest = Object.assign(oldManifest, manifest);
156-
}
145+
manifest = Object.assign(oldManifest, manifest);
146+
}
157147

158-
manifestFile.contents = Buffer.from(options.transformer.stringify(sortKeys(manifest), undefined, ' '));
148+
manifestFile.contents = Buffer.from(options.transformer.stringify(sortKeys(manifest), undefined, ' '));
159149

160-
yield manifestFile;
150+
yield manifestFile;
151+
},
161152
});
162153
};
163-
164-
export default plugin;

‎package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type": "module",
1414
"exports": "./index.js",
1515
"engines": {
16-
"node": ">=16"
16+
"node": ">=18"
1717
},
1818
"scripts": {
1919
"test": "xo && ava"
@@ -37,19 +37,18 @@
3737
"assets"
3838
],
3939
"dependencies": {
40-
"easy-transform-stream": "^1.0.0",
40+
"gulp-plugin-extras": "^0.3.0",
4141
"modify-filename": "^2.0.0",
42-
"plugin-error": "^2.0.1",
43-
"rev-hash": "^4.0.0",
42+
"rev-hash": "^4.1.0",
4443
"rev-path": "^3.0.0",
4544
"sort-keys": "^5.0.0",
4645
"vinyl": "^3.0.0",
4746
"vinyl-file": "^5.0.0"
4847
},
4948
"devDependencies": {
50-
"ava": "^5.1.0",
51-
"p-event": "^5.0.1",
52-
"xo": "^0.53.1"
49+
"ava": "^5.3.1",
50+
"p-event": "^6.0.0",
51+
"xo": "^0.56.0"
5352
},
5453
"peerDependencies": {
5554
"gulp": ">=4"

0 commit comments

Comments
 (0)
Please sign in to comment.