webpack-assets-manifest 6.3.0 → 6.5.0

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) {
@@ -266,7 +272,7 @@ class WebpackAssetsManifest {
266
272
  const infraLogger = compilation.compiler.getInfrastructureLogger(PLUGIN_NAME);
267
273
  for (const module of modules) {
268
274
  if (module instanceof NormalModule) {
269
- const codeGenData = codeGenerationResults.get(module, chunk.runtime).data;
275
+ const codeGenData = codeGenerationResults?.get(module, chunk.runtime).data;
270
276
  const filename = module.buildInfo?.['filename'] ?? codeGenData?.get('filename');
271
277
  if (!filename) {
272
278
  infraLogger.warn(`Unable to get filename from module: "${module.rawRequest}"`);
@@ -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) {
@@ -230,7 +236,7 @@ export class WebpackAssetsManifest {
230
236
  const infraLogger = compilation.compiler.getInfrastructureLogger(PLUGIN_NAME);
231
237
  for (const module of modules) {
232
238
  if (module instanceof NormalModule) {
233
- const codeGenData = codeGenerationResults.get(module, chunk.runtime).data;
239
+ const codeGenData = codeGenerationResults?.get(module, chunk.runtime).data;
234
240
  const filename = module.buildInfo?.['filename'] ?? codeGenData?.get('filename');
235
241
  if (!filename) {
236
242
  infraLogger.warn(`Unable to get filename from module: "${module.rawRequest}"`);
@@ -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.3.0",
3
+ "version": "6.5.0",
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,7 +65,7 @@
65
65
  "files": [
66
66
  "dist"
67
67
  ],
68
- "packageManager": "pnpm@10.17.1+sha512.17c560fca4867ae9473a3899ad84a88334914f379be46d455cbf92e5cf4b39d34985d452d2583baf19967fa76cb5c17bc9e245529d0b98745721aa7200ecaf7a",
68
+ "packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a",
69
69
  "scripts": {
70
70
  "clean": "rimraf ./coverage/ ./dist/ ./cache/",
71
71
  "prebuild": "pnpm clean",
@@ -85,29 +85,29 @@
85
85
  "prettier": "@webdeveric/prettier-config",
86
86
  "dependencies": {
87
87
  "deepmerge": "^4.3.1",
88
- "lockfile": "^1.0.4",
89
- "schema-utils": "^4.3.2",
90
- "tapable": "^2.2.3"
88
+ "proper-lockfile": "^4.1.2",
89
+ "schema-utils": "^4.3.3",
90
+ "tapable": "^2.3.0"
91
91
  },
92
92
  "peerDependencies": {
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.17",
100
- "@types/tapable": "^2.2.7",
96
+ "@commitlint/config-conventional": "^20.2.0",
97
+ "@commitlint/types": "^20.2.0",
98
+ "@types/node": "^20.19.25",
99
+ "@types/proper-lockfile": "^4.1.4",
100
+ "@types/tapable": "^2.3.0",
101
101
  "@types/webpack-sources": "^3.2.3",
102
- "@vitest/coverage-v8": "^3.2.4",
102
+ "@vitest/coverage-v8": "^4.0.15",
103
103
  "@webdeveric/eslint-config-ts": "^0.11.0",
104
104
  "@webdeveric/prettier-config": "^0.3.0",
105
- "commitlint": "^20.0.0",
105
+ "commitlint": "^20.2.0",
106
106
  "commitlint-plugin-cspell": "^0.3.0",
107
107
  "compression-webpack-plugin": "^11.1.0",
108
108
  "conventional-changelog-conventionalcommits": "^9.1.0",
109
109
  "copy-webpack-plugin": "^13.0.1",
110
- "cspell": "^9.2.1",
110
+ "cspell": "^9.4.0",
111
111
  "css-loader": "^7.1.2",
112
112
  "eslint": "^8.57.1",
113
113
  "eslint-config-prettier": "^10.1.8",
@@ -116,17 +116,17 @@
116
116
  "file-loader": "^6.2.0",
117
117
  "fs-extra": "^11.3.2",
118
118
  "husky": "^9.1.7",
119
- "lint-staged": "^16.2.1",
120
- "memfs": "^4.47.0",
119
+ "lint-staged": "^16.2.7",
120
+ "memfs": "^4.51.1",
121
121
  "mini-css-extract-plugin": "^2.9.4",
122
- "prettier": "^3.6.2",
123
- "rimraf": "^6.0.1",
124
- "sass-loader": "^16.0.5",
122
+ "prettier": "^3.7.4",
123
+ "rimraf": "^6.1.2",
124
+ "sass-loader": "^16.0.6",
125
125
  "semantic-release": "^24.2.9",
126
- "typescript": "^5.9.2",
127
- "validate-package-exports": "^0.13.0",
128
- "vitest": "^3.2.4",
129
- "webpack": "^5.101.3",
126
+ "typescript": "^5.9.3",
127
+ "validate-package-exports": "^0.14.0",
128
+ "vitest": "^4.0.15",
129
+ "webpack": "^5.103.0",
130
130
  "webpack-dev-server": "^5.2.2",
131
131
  "webpack-subresource-integrity": "^5.1.0"
132
132
  },