webpack-assets-manifest 6.4.0 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,13 +5,7 @@ exports.getSRIHash = getSRIHash;
5
5
  exports.getSortedObject = getSortedObject;
6
6
  exports.findMapKeysByValue = findMapKeysByValue;
7
7
  exports.group = group;
8
- exports.getLockFilename = getLockFilename;
9
- exports.lock = lock;
10
- exports.unlock = unlock;
11
8
  const node_crypto_1 = require("node:crypto");
12
- const node_os_1 = require("node:os");
13
- const node_path_1 = require("node:path");
14
- const lockfile_1 = require("lockfile");
15
9
  const type_predicate_js_1 = require("./type-predicate.js");
16
10
  function asArray(data) {
17
11
  return Array.isArray(data) ? data : [data];
@@ -35,34 +29,3 @@ function group(data, getGroup, mapper) {
35
29
  return obj;
36
30
  }, Object.create(null));
37
31
  }
38
- function getLockFilename(filename) {
39
- const name = filename.replace(/[^\w]+/g, '-');
40
- return (0, node_path_1.join)((0, node_os_1.tmpdir)(), `${name}.lock`);
41
- }
42
- function lock(filename) {
43
- return new Promise((resolve, reject) => {
44
- (0, lockfile_1.lock)(getLockFilename(filename), {
45
- wait: 10000,
46
- stale: 20000,
47
- retries: 100,
48
- retryWait: 100,
49
- }, (error) => {
50
- if (error) {
51
- reject(error);
52
- return;
53
- }
54
- resolve();
55
- });
56
- });
57
- }
58
- function unlock(filename) {
59
- return new Promise((resolve, reject) => {
60
- (0, lockfile_1.unlock)(getLockFilename(filename), (error) => {
61
- if (error) {
62
- reject(error);
63
- return;
64
- }
65
- resolve();
66
- });
67
- });
68
- }
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.WebpackAssetsManifest = void 0;
37
37
  const promises_1 = require("node:fs/promises");
38
38
  const node_path_1 = require("node:path");
39
+ const proper_lockfile_1 = require("proper-lockfile");
39
40
  const schema_utils_1 = require("schema-utils");
40
41
  const tapable_1 = require("tapable");
41
42
  const helpers_js_1 = require("./helpers.js");
@@ -243,17 +244,22 @@ class WebpackAssetsManifest {
243
244
  async emitAssetsManifest(compilation) {
244
245
  const outputPath = this.getOutputPath();
245
246
  const output = this.getManifestPath(compilation, this.inDevServer() ? (0, node_path_1.basename)(this.options.output) : (0, node_path_1.relative)(compilation.compiler.outputPath, outputPath));
246
- if (this.options.merge) {
247
- await (0, helpers_js_1.lock)(outputPath);
247
+ let release;
248
+ try {
249
+ if (this.options.merge) {
250
+ const outputDir = (0, node_path_1.dirname)(outputPath);
251
+ await (0, promises_1.mkdir)(outputDir, { recursive: true });
252
+ release = await (0, proper_lockfile_1.lock)(outputDir, { lockfilePath: (0, node_path_1.join)(outputDir, `${PLUGIN_NAME}.lock`) });
253
+ }
254
+ await this.maybeMerge();
255
+ compilation.emitAsset(output, new compilation.compiler.webpack.sources.RawSource(this.toString(), false), {
256
+ assetsManifest: true,
257
+ generated: true,
258
+ generatedBy: [PLUGIN_NAME],
259
+ });
248
260
  }
249
- await this.maybeMerge();
250
- compilation.emitAsset(output, new compilation.compiler.webpack.sources.RawSource(this.toString(), false), {
251
- assetsManifest: true,
252
- generated: true,
253
- generatedBy: [PLUGIN_NAME],
254
- });
255
- if (this.options.merge) {
256
- await (0, helpers_js_1.unlock)(outputPath);
261
+ finally {
262
+ await release?.();
257
263
  }
258
264
  }
259
265
  handleProcessAssetsAnalyse(compilation) {
@@ -387,10 +393,16 @@ class WebpackAssetsManifest {
387
393
  });
388
394
  }
389
395
  async writeTo(destination) {
390
- await (0, helpers_js_1.lock)(destination);
391
- await (0, promises_1.mkdir)((0, node_path_1.dirname)(destination), { recursive: true });
392
- await (0, promises_1.writeFile)(destination, this.toString());
393
- await (0, helpers_js_1.unlock)(destination);
396
+ const destinationDir = (0, node_path_1.dirname)(destination);
397
+ let release;
398
+ try {
399
+ await (0, promises_1.mkdir)(destinationDir, { recursive: true });
400
+ release = await (0, proper_lockfile_1.lock)(destinationDir, { lockfilePath: (0, node_path_1.join)(destinationDir, `${PLUGIN_NAME}.lock`) });
401
+ await (0, promises_1.writeFile)(destination, this.toString());
402
+ }
403
+ finally {
404
+ await release?.();
405
+ }
394
406
  }
395
407
  clear() {
396
408
  Object.keys(this.assets).forEach((key) => {
@@ -1,7 +1,4 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import { lock as lockfileLock, unlock as lockfileUnlock } from 'lockfile';
5
2
  import { isPropertyKey } from './type-predicate.js';
6
3
  export function asArray(data) {
7
4
  return Array.isArray(data) ? data : [data];
@@ -25,34 +22,3 @@ export function group(data, getGroup, mapper) {
25
22
  return obj;
26
23
  }, Object.create(null));
27
24
  }
28
- export function getLockFilename(filename) {
29
- const name = filename.replace(/[^\w]+/g, '-');
30
- return join(tmpdir(), `${name}.lock`);
31
- }
32
- export function lock(filename) {
33
- return new Promise((resolve, reject) => {
34
- lockfileLock(getLockFilename(filename), {
35
- wait: 10000,
36
- stale: 20000,
37
- retries: 100,
38
- retryWait: 100,
39
- }, (error) => {
40
- if (error) {
41
- reject(error);
42
- return;
43
- }
44
- resolve();
45
- });
46
- });
47
- }
48
- export function unlock(filename) {
49
- return new Promise((resolve, reject) => {
50
- lockfileUnlock(getLockFilename(filename), (error) => {
51
- if (error) {
52
- reject(error);
53
- return;
54
- }
55
- resolve();
56
- });
57
- });
58
- }
@@ -1,8 +1,9 @@
1
1
  import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
2
  import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
3
+ import { lock } from 'proper-lockfile';
3
4
  import { validate } from 'schema-utils';
4
5
  import { AsyncSeriesHook, SyncHook, SyncWaterfallHook } from 'tapable';
5
- import { asArray, findMapKeysByValue, getSortedObject, getSRIHash, group, lock, unlock } from './helpers.js';
6
+ import { asArray, findMapKeysByValue, getSortedObject, getSRIHash, group } from './helpers.js';
6
7
  import { optionsSchema } from './options-schema.js';
7
8
  import { isKeyValuePair, isObject } from './type-predicate.js';
8
9
  const PLUGIN_NAME = 'WebpackAssetsManifest';
@@ -207,17 +208,22 @@ export class WebpackAssetsManifest {
207
208
  async emitAssetsManifest(compilation) {
208
209
  const outputPath = this.getOutputPath();
209
210
  const output = this.getManifestPath(compilation, this.inDevServer() ? basename(this.options.output) : relative(compilation.compiler.outputPath, outputPath));
210
- if (this.options.merge) {
211
- await lock(outputPath);
211
+ let release;
212
+ try {
213
+ if (this.options.merge) {
214
+ const outputDir = dirname(outputPath);
215
+ await mkdir(outputDir, { recursive: true });
216
+ release = await lock(outputDir, { lockfilePath: join(outputDir, `${PLUGIN_NAME}.lock`) });
217
+ }
218
+ await this.maybeMerge();
219
+ compilation.emitAsset(output, new compilation.compiler.webpack.sources.RawSource(this.toString(), false), {
220
+ assetsManifest: true,
221
+ generated: true,
222
+ generatedBy: [PLUGIN_NAME],
223
+ });
212
224
  }
213
- await this.maybeMerge();
214
- compilation.emitAsset(output, new compilation.compiler.webpack.sources.RawSource(this.toString(), false), {
215
- assetsManifest: true,
216
- generated: true,
217
- generatedBy: [PLUGIN_NAME],
218
- });
219
- if (this.options.merge) {
220
- await unlock(outputPath);
225
+ finally {
226
+ await release?.();
221
227
  }
222
228
  }
223
229
  handleProcessAssetsAnalyse(compilation) {
@@ -351,10 +357,16 @@ export class WebpackAssetsManifest {
351
357
  });
352
358
  }
353
359
  async writeTo(destination) {
354
- await lock(destination);
355
- await mkdir(dirname(destination), { recursive: true });
356
- await writeFile(destination, this.toString());
357
- await unlock(destination);
360
+ const destinationDir = dirname(destination);
361
+ let release;
362
+ try {
363
+ await mkdir(destinationDir, { recursive: true });
364
+ release = await lock(destinationDir, { lockfilePath: join(destinationDir, `${PLUGIN_NAME}.lock`) });
365
+ await writeFile(destination, this.toString());
366
+ }
367
+ finally {
368
+ await release?.();
369
+ }
358
370
  }
359
371
  clear() {
360
372
  Object.keys(this.assets).forEach((key) => {
@@ -4,6 +4,3 @@ export declare function getSRIHash(algorithm: string, content: string | BinaryLi
4
4
  export declare function getSortedObject(object: Record<string, unknown>, compareFunction?: (left: string, right: string) => number): typeof object;
5
5
  export declare function findMapKeysByValue<K = string, V = string>(map: Map<K, V>): (searchValue: V) => K[];
6
6
  export declare function group<T>(data: readonly T[], getGroup: (item: T) => PropertyKey | undefined, mapper?: (item: T, group: PropertyKey) => T): Record<PropertyKey, T[]>;
7
- export declare function getLockFilename(filename: string): string;
8
- export declare function lock(filename: string): Promise<void>;
9
- export declare function unlock(filename: string): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-assets-manifest",
3
- "version": "6.4.0",
3
+ "version": "6.5.1",
4
4
  "description": "This Webpack plugin will generate a JSON file that matches the original filename with the hashed version.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -65,11 +65,11 @@
65
65
  "files": [
66
66
  "dist"
67
67
  ],
68
- "packageManager": "pnpm@10.20.0+sha512.cf9998222162dd85864d0a8102e7892e7ba4ceadebbf5a31f9c2fce48dfce317a9c53b9f6464d1ef9042cba2e02ae02a9f7c143a2b438cd93c91840f0192b9dd",
68
+ "packageManager": "pnpm@10.31.0+sha512.e3927388bfaa8078ceb79b748ffc1e8274e84d75163e67bc22e06c0d3aed43dd153151cbf11d7f8301ff4acb98c68bdc5cadf6989532801ffafe3b3e4a63c268",
69
69
  "scripts": {
70
70
  "clean": "rimraf ./coverage/ ./dist/ ./cache/",
71
71
  "prebuild": "pnpm clean",
72
- "validate": "validate-package-exports --check --verify --info",
72
+ "validate": "validate-package-exports --check --info",
73
73
  "build": "tsc --build tsconfig.cjs.json tsconfig.mjs.json --force",
74
74
  "postbuild": "node postbuild.mjs && pnpm validate",
75
75
  "lint": "eslint \"./*.{js,cjs,mjs,ts,cts,mts}\" ./src ./test ./examples",
@@ -85,7 +85,7 @@
85
85
  "prettier": "@webdeveric/prettier-config",
86
86
  "dependencies": {
87
87
  "deepmerge": "^4.3.1",
88
- "lockfile": "^1.0.4",
88
+ "proper-lockfile": "^4.1.2",
89
89
  "schema-utils": "^4.3.3",
90
90
  "tapable": "^2.3.0"
91
91
  },
@@ -93,47 +93,50 @@
93
93
  "webpack": "^5.61.0"
94
94
  },
95
95
  "devDependencies": {
96
- "@commitlint/config-conventional": "^20.0.0",
97
- "@commitlint/types": "^20.0.0",
98
- "@types/lockfile": "^1.0.4",
99
- "@types/node": "^20.19.24",
96
+ "@commitlint/config-conventional": "^20.4.3",
97
+ "@commitlint/types": "^20.4.3",
98
+ "@types/node": "^20.19.37",
99
+ "@types/proper-lockfile": "^4.1.4",
100
100
  "@types/tapable": "^2.3.0",
101
101
  "@types/webpack-sources": "^3.2.3",
102
- "@vitest/coverage-v8": "^3.2.4",
103
- "@webdeveric/eslint-config-ts": "^0.11.0",
102
+ "@vitest/coverage-v8": "^4.0.18",
103
+ "@webdeveric/eslint-config-ts": "^0.12.0",
104
104
  "@webdeveric/prettier-config": "^0.3.0",
105
- "commitlint": "^20.1.0",
106
- "commitlint-plugin-cspell": "^0.3.0",
107
- "compression-webpack-plugin": "^11.1.0",
108
- "conventional-changelog-conventionalcommits": "^9.1.0",
109
- "copy-webpack-plugin": "^13.0.1",
110
- "cspell": "^9.3.0",
111
- "css-loader": "^7.1.2",
105
+ "commitlint": "^20.4.3",
106
+ "commitlint-plugin-cspell": "^0.6.0",
107
+ "compression-webpack-plugin": "^12.0.0",
108
+ "conventional-changelog-conventionalcommits": "^9.3.0",
109
+ "copy-webpack-plugin": "^14.0.0",
110
+ "cspell": "^9.7.0",
111
+ "css-loader": "^7.1.4",
112
112
  "eslint": "^8.57.1",
113
113
  "eslint-config-prettier": "^10.1.8",
114
114
  "eslint-import-resolver-typescript": "^4.4.4",
115
115
  "eslint-plugin-import": "^2.32.0",
116
116
  "file-loader": "^6.2.0",
117
- "fs-extra": "^11.3.2",
117
+ "fs-extra": "^11.3.4",
118
118
  "husky": "^9.1.7",
119
- "lint-staged": "^16.2.6",
120
- "memfs": "^4.50.0",
121
- "mini-css-extract-plugin": "^2.9.4",
122
- "prettier": "^3.6.2",
123
- "rimraf": "^6.1.0",
124
- "sass-loader": "^16.0.6",
125
- "semantic-release": "^24.2.9",
119
+ "lint-staged": "^16.3.2",
120
+ "memfs": "^4.56.11",
121
+ "mini-css-extract-plugin": "^2.10.0",
122
+ "prettier": "^3.8.1",
123
+ "rimraf": "^6.1.3",
124
+ "sass-loader": "^16.0.7",
125
+ "semantic-release": "^25.0.3",
126
126
  "typescript": "^5.9.3",
127
- "validate-package-exports": "^0.14.0",
128
- "vitest": "^3.2.4",
129
- "webpack": "^5.102.1",
130
- "webpack-dev-server": "^5.2.2",
127
+ "validate-package-exports": "^0.19.1",
128
+ "vitest": "^4.0.18",
129
+ "webpack": "^5.105.4",
130
+ "webpack-dev-server": "^5.2.3",
131
131
  "webpack-subresource-integrity": "^5.1.0"
132
132
  },
133
133
  "pnpm": {
134
134
  "onlyBuiltDependencies": [
135
135
  "esbuild",
136
136
  "unrs-resolver"
137
- ]
137
+ ],
138
+ "overrides": {
139
+ "serialize-javascript@<=7.0.2": ">=7.0.3"
140
+ }
138
141
  }
139
142
  }