@serwist/build 9.0.6 → 9.0.7

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import stringify from "fast-json-stable-stringify";
2
1
  import { getManifest } from "./get-manifest.js";
3
2
  import { injectManifest } from "./inject-manifest.js";
4
3
  import { errors } from "./lib/errors.js";
@@ -10,6 +9,15 @@ import { replaceAndUpdateSourceMap } from "./lib/replace-and-update-source-map.j
10
9
  import { transformManifest } from "./lib/transform-manifest.js";
11
10
  import { translateURLToSourcemapPaths } from "./lib/translate-url-to-sourcemap-paths.js";
12
11
  import { validateGetManifestOptions, validateInjectManifestOptions } from "./lib/validate-options.js";
12
+ /**
13
+ * Use `JSON.stringify` instead.
14
+ *
15
+ * @deprecated
16
+ */
17
+ declare const stringify: {
18
+ (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
19
+ (value: any, replacer?: (number | string)[] | null, space?: string | number): string;
20
+ };
13
21
  export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, stringify, transformManifest, translateURLToSourcemapPaths, validateGetManifestOptions, validateInjectManifestOptions, };
14
22
  export type * from "./types.js";
15
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,SAAS,MAAM,4BAA4B,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAEtG,OAAO,EACL,MAAM,EACN,YAAY,EACZ,sBAAsB,EACtB,WAAW,EACX,eAAe,EACf,cAAc,EACd,UAAU,EACV,yBAAyB,EACzB,SAAS,EACT,iBAAiB,EACjB,4BAA4B,EAC5B,0BAA0B,EAC1B,6BAA6B,GAC9B,CAAC;AAEF,mBAAmB,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAGtG;;;;GAIG;AACH,QAAA,MAAM,SAAS;;;CAAiB,CAAC;AAEjC,OAAO,EACL,MAAM,EACN,YAAY,EACZ,sBAAsB,EACtB,WAAW,EACX,eAAe,EACf,cAAc,EACd,UAAU,EACV,yBAAyB,EACzB,SAAS,EACT,iBAAiB,EACjB,4BAA4B,EAC5B,0BAA0B,EAC1B,6BAA6B,GAC9B,CAAC;AAEF,mBAAmB,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,15 +1,12 @@
1
- import stringify from 'fast-json-stable-stringify';
2
- export { default as stringify } from 'fast-json-stable-stringify';
3
1
  import assert from 'node:assert';
4
2
  import { oneLine } from 'common-tags';
5
3
  import crypto from 'node:crypto';
6
4
  import path from 'node:path';
7
5
  import { globSync } from 'glob';
8
- import { readFileSync } from 'node:fs';
9
- import fse from 'fs-extra';
6
+ import fs, { readFileSync } from 'node:fs';
10
7
  import prettyBytes from 'pretty-bytes';
11
8
  import { v as validationErrorMap, S as SerwistConfigError } from './chunks/validationErrorMap.js';
12
- import upath from 'upath';
9
+ import fsp from 'node:fs/promises';
13
10
  import { SourceMapGenerator, SourceMapConsumer } from 'source-map';
14
11
  import 'zod';
15
12
 
@@ -129,9 +126,9 @@ const getFileHash = (file)=>{
129
126
  }
130
127
  };
131
128
 
132
- function getFileSize(file) {
129
+ const getFileSize = (file)=>{
133
130
  try {
134
- const stat = fse.statSync(file);
131
+ const stat = fs.statSync(file);
135
132
  if (!stat.isFile()) {
136
133
  return null;
137
134
  }
@@ -139,7 +136,7 @@ function getFileSize(file) {
139
136
  } catch (err) {
140
137
  throw new Error(`${errors["unable-to-get-file-size"]} '${err instanceof Error && err.message ? err.message : ""}'`);
141
138
  }
142
- }
139
+ };
143
140
 
144
141
  const getFileDetails = ({ globDirectory, globFollow, globIgnores, globPattern })=>{
145
142
  let globbedFiles;
@@ -460,6 +457,10 @@ const getManifest = async (config)=>{
460
457
  return await getFileManifestEntries(options);
461
458
  };
462
459
 
460
+ const toUnix = (p)=>{
461
+ return p.replace(/\\/g, "/").replace(/(?<!^)\/+/g, "/");
462
+ };
463
+
463
464
  const innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/;
464
465
  const regex = RegExp(`(?:/\\*(?:\\s*\r?\n(?://)?)?(?:${innerRegex.source})\\s*\\*/|//(?:${innerRegex.source}))\\s*`);
465
466
  function getSourceMapURL(srcContents) {
@@ -468,10 +469,10 @@ function getSourceMapURL(srcContents) {
468
469
  }
469
470
 
470
471
  function rebasePath({ baseDirectory, file }) {
471
- const absolutePath = upath.resolve(file);
472
- const relativePath = upath.relative(baseDirectory, absolutePath);
473
- const normalizedPath = upath.normalize(relativePath);
474
- return normalizedPath;
472
+ const absolutePath = path.resolve(file);
473
+ const relativePath = path.relative(baseDirectory, absolutePath);
474
+ const normalizedPath = path.normalize(relativePath);
475
+ return toUnix(normalizedPath);
475
476
  }
476
477
 
477
478
  async function replaceAndUpdateSourceMap({ jsFilename, originalMap, originalSource, replaceString, searchString }) {
@@ -541,10 +542,10 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
541
542
  let srcPath = undefined;
542
543
  let warning = undefined;
543
544
  if (url && !url.startsWith("data:")) {
544
- const possibleSrcPath = upath.resolve(upath.dirname(swSrc), url);
545
- if (fse.existsSync(possibleSrcPath)) {
546
- srcPath = possibleSrcPath;
547
- destPath = upath.resolve(upath.dirname(swDest), url);
545
+ const possibleSrcPath = path.resolve(path.dirname(swSrc), url);
546
+ if (fs.existsSync(possibleSrcPath)) {
547
+ srcPath = toUnix(possibleSrcPath);
548
+ destPath = toUnix(path.resolve(path.dirname(swDest), url));
548
549
  } else {
549
550
  warning = `${errors["cant-find-sourcemap"]} ${possibleSrcPath}`;
550
551
  }
@@ -571,20 +572,20 @@ const injectManifest = async (config)=>{
571
572
  const { count, size, manifestEntries, warnings } = await getFileManifestEntries(options);
572
573
  let swFileContents;
573
574
  try {
574
- swFileContents = await fse.readFile(options.swSrc, "utf8");
575
+ swFileContents = await fsp.readFile(options.swSrc, "utf8");
575
576
  } catch (error) {
576
577
  throw new Error(`${errors["invalid-sw-src"]} ${error instanceof Error && error.message ? error.message : ""}`);
577
578
  }
578
579
  const injectionResults = swFileContents.match(globalRegexp);
579
580
  const injectionPoint = options.injectionPoint ? options.injectionPoint : "";
580
581
  if (!injectionResults) {
581
- if (upath.resolve(options.swSrc) === upath.resolve(options.swDest)) {
582
+ if (path.resolve(options.swSrc) === path.resolve(options.swDest)) {
582
583
  throw new Error(`${errors["same-src-and-dest"]} ${injectionPoint}`);
583
584
  }
584
585
  throw new Error(`${errors["injection-point-not-found"]} ${injectionPoint}`);
585
586
  }
586
587
  assert(injectionResults.length === 1, `${errors["multiple-injection-points"]} ${injectionPoint}`);
587
- const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
588
+ const manifestString = manifestEntries === undefined ? "undefined" : JSON.stringify(manifestEntries);
588
589
  const filesToWrite = {};
589
590
  const url = getSourceMapURL(swFileContents);
590
591
  const { destPath, srcPath, warning } = translateURLToSourcemapPaths(url, options.swSrc, options.swDest);
@@ -592,12 +593,10 @@ const injectManifest = async (config)=>{
592
593
  warnings.push(warning);
593
594
  }
594
595
  if (srcPath && destPath) {
595
- const originalMap = await fse.readJSON(srcPath, {
596
- encoding: "utf8"
597
- });
596
+ const originalMap = JSON.parse(await fsp.readFile(srcPath, "utf-8"));
598
597
  const { map, source } = await replaceAndUpdateSourceMap({
599
598
  originalMap,
600
- jsFilename: upath.basename(options.swDest),
599
+ jsFilename: toUnix(path.basename(options.swDest)),
601
600
  originalSource: swFileContents,
602
601
  replaceString: manifestString,
603
602
  searchString: options.injectionPoint
@@ -609,18 +608,22 @@ const injectManifest = async (config)=>{
609
608
  }
610
609
  for (const [file, contents] of Object.entries(filesToWrite)){
611
610
  try {
612
- await fse.mkdirp(upath.dirname(file));
611
+ await fsp.mkdir(path.dirname(file), {
612
+ recursive: true
613
+ });
613
614
  } catch (error) {
614
615
  throw new Error(`${errors["unable-to-make-sw-directory"]} '${error instanceof Error && error.message ? error.message : ""}'`);
615
616
  }
616
- await fse.writeFile(file, contents);
617
+ await fsp.writeFile(file, contents);
617
618
  }
618
619
  return {
619
620
  count,
620
621
  size,
621
622
  warnings,
622
- filePaths: Object.keys(filesToWrite).map((f)=>upath.resolve(f))
623
+ filePaths: Object.keys(filesToWrite).map((f)=>toUnix(path.resolve(f)))
623
624
  };
624
625
  };
625
626
 
626
- export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, transformManifest, translateURLToSourcemapPaths, validateGetManifestOptions, validateInjectManifestOptions };
627
+ const stringify = JSON.stringify;
628
+
629
+ export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, stringify, transformManifest, translateURLToSourcemapPaths, validateGetManifestOptions, validateInjectManifestOptions };
@@ -1 +1 @@
1
- {"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc,WAAkB,qBAAqB,KAAG,OAAO,CAAC,WAAW,CAyFvF,CAAC"}
1
+ {"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc,WAAkB,qBAAqB,KAAG,OAAO,CAAC,WAAW,CAwFvF,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare function getFileSize(file: string): number | null;
1
+ export declare const getFileSize: (file: string) => number | null;
2
2
  //# sourceMappingURL=get-file-size.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-file-size.d.ts","sourceRoot":"","sources":["../../src/lib/get-file-size.ts"],"names":[],"mappings":"AAYA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUvD"}
1
+ {"version":3,"file":"get-file-size.d.ts","sourceRoot":"","sources":["../../src/lib/get-file-size.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,MAAM,GAAG,IAUnD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"rebase-path.d.ts","sourceRoot":"","sources":["../../src/lib/rebase-path.ts"],"names":[],"mappings":"AAUA,wBAAgB,UAAU,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAWnG"}
1
+ {"version":3,"file":"rebase-path.d.ts","sourceRoot":"","sources":["../../src/lib/rebase-path.ts"],"names":[],"mappings":"AAWA,wBAAgB,UAAU,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAWnG"}
@@ -1 +1 @@
1
- {"version":3,"file":"translate-url-to-sourcemap-paths.d.ts","sourceRoot":"","sources":["../../src/lib/translate-url-to-sourcemap-paths.ts"],"names":[],"mappings":"AAaA,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb;IACD,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAgBA"}
1
+ {"version":3,"file":"translate-url-to-sourcemap-paths.d.ts","sourceRoot":"","sources":["../../src/lib/translate-url-to-sourcemap-paths.ts"],"names":[],"mappings":"AAYA,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb;IACD,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAgBA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/build",
3
- "version": "9.0.6",
3
+ "version": "9.0.7",
4
4
  "type": "module",
5
5
  "description": "A module that integrates into your build process, helping you generate a manifest of local files that should be precached.",
6
6
  "files": [
@@ -49,24 +49,19 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "common-tags": "1.8.2",
52
- "fast-json-stable-stringify": "2.1.0",
53
- "fs-extra": "11.2.0",
54
52
  "glob": "10.4.5",
55
53
  "pretty-bytes": "6.1.1",
56
54
  "rollup": "4.21.0",
57
55
  "source-map": "0.8.0-beta.0",
58
- "upath": "2.0.1",
59
56
  "zod": "3.23.8"
60
57
  },
61
58
  "devDependencies": {
62
59
  "@types/common-tags": "1.8.4",
63
- "@types/fs-extra": "11.0.4",
64
60
  "@types/node": "22.5.0",
65
- "@types/stringify-object": "4.0.5",
66
61
  "type-fest": "4.25.0",
67
62
  "typescript": "5.5.4",
68
- "@serwist/configs": "9.0.6",
69
- "@serwist/utils": "9.0.6"
63
+ "@serwist/configs": "9.0.7",
64
+ "@serwist/utils": "9.0.7"
70
65
  },
71
66
  "peerDependencies": {
72
67
  "typescript": ">=5.0.0"
package/src/index.ts CHANGED
@@ -5,8 +5,6 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
- import stringify from "fast-json-stable-stringify";
9
-
10
8
  import { getManifest } from "./get-manifest.js";
11
9
  import { injectManifest } from "./inject-manifest.js";
12
10
  import { errors } from "./lib/errors.js";
@@ -19,6 +17,14 @@ import { transformManifest } from "./lib/transform-manifest.js";
19
17
  import { translateURLToSourcemapPaths } from "./lib/translate-url-to-sourcemap-paths.js";
20
18
  import { validateGetManifestOptions, validateInjectManifestOptions } from "./lib/validate-options.js";
21
19
 
20
+ // TODO: remove in v10.
21
+ /**
22
+ * Use `JSON.stringify` instead.
23
+ *
24
+ * @deprecated
25
+ */
26
+ const stringify = JSON.stringify;
27
+
22
28
  export {
23
29
  errors,
24
30
  escapeRegExp,
@@ -5,13 +5,11 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
-
9
8
  import assert from "node:assert";
10
- import stringify from "fast-json-stable-stringify";
11
- import fse from "fs-extra";
9
+ import fsp from "node:fs/promises";
10
+ import path from "node:path";
11
+ import { toUnix } from "@serwist/utils";
12
12
  import type { RawSourceMap } from "source-map";
13
- import upath from "upath";
14
-
15
13
  import { errors } from "./lib/errors.js";
16
14
  import { escapeRegExp } from "./lib/escape-regexp.js";
17
15
  import { getFileManifestEntries } from "./lib/get-file-manifest-entries.js";
@@ -66,7 +64,7 @@ export const injectManifest = async (config: InjectManifestOptions): Promise<Bui
66
64
  const { count, size, manifestEntries, warnings } = await getFileManifestEntries(options);
67
65
  let swFileContents: string;
68
66
  try {
69
- swFileContents = await fse.readFile(options.swSrc, "utf8");
67
+ swFileContents = await fsp.readFile(options.swSrc, "utf8");
70
68
  } catch (error) {
71
69
  throw new Error(`${errors["invalid-sw-src"]} ${error instanceof Error && error.message ? error.message : ""}`);
72
70
  }
@@ -75,7 +73,7 @@ export const injectManifest = async (config: InjectManifestOptions): Promise<Bui
75
73
  // See https://github.com/GoogleChrome/workbox/issues/2230
76
74
  const injectionPoint = options.injectionPoint ? options.injectionPoint : "";
77
75
  if (!injectionResults) {
78
- if (upath.resolve(options.swSrc) === upath.resolve(options.swDest)) {
76
+ if (path.resolve(options.swSrc) === path.resolve(options.swDest)) {
79
77
  throw new Error(`${errors["same-src-and-dest"]} ${injectionPoint}`);
80
78
  }
81
79
  throw new Error(`${errors["injection-point-not-found"]} ${injectionPoint}`);
@@ -83,7 +81,8 @@ export const injectManifest = async (config: InjectManifestOptions): Promise<Bui
83
81
 
84
82
  assert(injectionResults.length === 1, `${errors["multiple-injection-points"]} ${injectionPoint}`);
85
83
 
86
- const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
84
+ const manifestString = manifestEntries === undefined ? "undefined" : JSON.stringify(manifestEntries);
85
+
87
86
  const filesToWrite: { [key: string]: string } = {};
88
87
 
89
88
  const url = getSourceMapURL(swFileContents);
@@ -100,13 +99,11 @@ export const injectManifest = async (config: InjectManifestOptions): Promise<Bui
100
99
  // See https://github.com/GoogleChrome/workbox/issues/2235
101
100
  // and https://github.com/GoogleChrome/workbox/issues/2648
102
101
  if (srcPath && destPath) {
103
- const originalMap = (await fse.readJSON(srcPath, {
104
- encoding: "utf8",
105
- })) as RawSourceMap;
102
+ const originalMap = JSON.parse(await fsp.readFile(srcPath, "utf-8")) as RawSourceMap;
106
103
 
107
104
  const { map, source } = await replaceAndUpdateSourceMap({
108
105
  originalMap,
109
- jsFilename: upath.basename(options.swDest),
106
+ jsFilename: toUnix(path.basename(options.swDest)),
110
107
  originalSource: swFileContents,
111
108
  replaceString: manifestString,
112
109
  searchString: options.injectionPoint!,
@@ -122,19 +119,19 @@ export const injectManifest = async (config: InjectManifestOptions): Promise<Bui
122
119
 
123
120
  for (const [file, contents] of Object.entries(filesToWrite)) {
124
121
  try {
125
- await fse.mkdirp(upath.dirname(file));
122
+ await fsp.mkdir(path.dirname(file), { recursive: true });
126
123
  } catch (error: unknown) {
127
124
  throw new Error(`${errors["unable-to-make-sw-directory"]} '${error instanceof Error && error.message ? error.message : ""}'`);
128
125
  }
129
126
 
130
- await fse.writeFile(file, contents);
127
+ await fsp.writeFile(file, contents);
131
128
  }
132
129
 
133
130
  return {
134
131
  count,
135
132
  size,
136
133
  warnings,
137
- // Use upath.resolve() to make all the paths absolute.
138
- filePaths: Object.keys(filesToWrite).map((f) => upath.resolve(f)),
134
+ // Use path.resolve() to make all the paths absolute.
135
+ filePaths: Object.keys(filesToWrite).map((f) => toUnix(path.resolve(f))),
139
136
  };
140
137
  };
@@ -6,13 +6,12 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import fse from "fs-extra";
10
-
9
+ import fs from "node:fs";
11
10
  import { errors } from "./errors.js";
12
11
 
13
- export function getFileSize(file: string): number | null {
12
+ export const getFileSize = (file: string): number | null => {
14
13
  try {
15
- const stat = fse.statSync(file);
14
+ const stat = fs.statSync(file);
16
15
  if (!stat.isFile()) {
17
16
  return null;
18
17
  }
@@ -6,17 +6,18 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import upath from "upath";
9
+ import { toUnix } from "@serwist/utils";
10
+ import path from "node:path";
10
11
 
11
12
  export function rebasePath({ baseDirectory, file }: { baseDirectory: string; file: string }): string {
12
13
  // The initial path is relative to the current directory, so make it absolute.
13
- const absolutePath = upath.resolve(file);
14
+ const absolutePath = path.resolve(file);
14
15
 
15
16
  // Convert the absolute path so that it's relative to the baseDirectory.
16
- const relativePath = upath.relative(baseDirectory, absolutePath);
17
+ const relativePath = path.relative(baseDirectory, absolutePath);
17
18
 
18
19
  // Remove any leading ./ as it won't work in a glob pattern.
19
- const normalizedPath = upath.normalize(relativePath);
20
+ const normalizedPath = path.normalize(relativePath);
20
21
 
21
- return normalizedPath;
22
+ return toUnix(normalizedPath);
22
23
  }
@@ -5,10 +5,9 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
-
9
- import fse from "fs-extra";
10
- import upath from "upath";
11
-
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ import { toUnix } from "@serwist/utils";
12
11
  import { errors } from "./errors.js";
13
12
 
14
13
  export function translateURLToSourcemapPaths(
@@ -25,10 +24,10 @@ export function translateURLToSourcemapPaths(
25
24
  let warning: string | undefined = undefined;
26
25
 
27
26
  if (url && !url.startsWith("data:")) {
28
- const possibleSrcPath = upath.resolve(upath.dirname(swSrc), url);
29
- if (fse.existsSync(possibleSrcPath)) {
30
- srcPath = possibleSrcPath;
31
- destPath = upath.resolve(upath.dirname(swDest), url);
27
+ const possibleSrcPath = path.resolve(path.dirname(swSrc), url);
28
+ if (fs.existsSync(possibleSrcPath)) {
29
+ srcPath = toUnix(possibleSrcPath);
30
+ destPath = toUnix(path.resolve(path.dirname(swDest), url));
32
31
  } else {
33
32
  warning = `${errors["cant-find-sourcemap"]} ${possibleSrcPath}`;
34
33
  }