eleventy-auto-cache-buster 0.9.0 → 0.9.2

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.
@@ -2,7 +2,10 @@ const fs = require("fs");
2
2
  const path = require("path");
3
3
  const crypto = require("crypto");
4
4
  const glob = require("glob");
5
- const escape = require("regexp.escape");
5
+
6
+ const regexEscape = parseInt(process.versions.node.split(".")[0]) >= 24
7
+ ? RegExp.escape
8
+ : require("escape-string-regexp").default;
6
9
 
7
10
  let enableLogging = false;
8
11
  let algorithm = "md5";
@@ -100,7 +103,7 @@ function replaceAssetsInFile(fileData, filePath, assetPathsAndHashes, writeFunc)
100
103
  assetHash = assetHash.substring(0, hashTruncate);
101
104
  }
102
105
  // find and replace all instances of the asset URL
103
- const assetPathRegexString = escape(assetPath);
106
+ const assetPathRegexString = regexEscape(assetPath);
104
107
  const regexWithQueryString = new RegExp(`${assetPathRegexString}\\?`, 'g')
105
108
  const regexWithoutQueryString = new RegExp(`${assetPathRegexString}(?!\\?)`, 'g')
106
109
  const newOutputString = outputString
@@ -120,6 +123,11 @@ function replaceAssetsInFile(fileData, filePath, assetPathsAndHashes, writeFunc)
120
123
  }
121
124
  }
122
125
 
126
+ // Meant to normalise eleventt.after directories.output to dir.output style
127
+ function stripPath(path) {
128
+ return path.replace(/^\.\//m, "");
129
+ }
130
+
123
131
  module.exports = function(eleventyConfig, options=defaultOptions) {
124
132
  // Override default options with set options
125
133
  options = Object.assign(defaultOptions, options, {
@@ -143,8 +151,9 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
143
151
 
144
152
  if (runAsync) {
145
153
  eleventyConfig.on("eleventy.after", async ({ directories, results, runMode, outputMode }) => {
146
- logYellow(`[ACB] Collecting assets & calculating hashes using ${globstring} in ${directories.output}...`);
147
- const assetPathsAndHashes = collectLocalAssets(await glob.glob(directories.output + "/" + globstring, globOptions), directories.output, extensions);
154
+ const outputDir = stripPath(directories.output);
155
+ logYellow(`[ACB] Collecting assets & calculating hashes using ${globstring} in ${outputDir}...`);
156
+ const assetPathsAndHashes = collectLocalAssets(await glob.glob(outputDir + "/" + globstring, globOptions), outputDir, extensions);
148
157
 
149
158
  logRegular(`[ACB] Replacing in output...`);
150
159
  results.forEach(({inputPath, outputPath, url, content}) => {
@@ -162,8 +171,9 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
162
171
  });
163
172
  } else {
164
173
  eleventyConfig.on("eleventy.after", ({ directories, results, runMode, outputMode }) => {
174
+ const outputDir = stripPath(directories.output);
165
175
  logYellow(`[ACB] Collecting assets & calculating hashes using ${globstring}...`);
166
- const assetPathsAndHashes = collectLocalAssets(glob.globSync(directories.output + "/" + globstring, globOptions), directories.output, extensions);
176
+ const assetPathsAndHashes = collectLocalAssets(glob.globSync(outputDir + "/" + globstring, globOptions), outputDir, extensions);
167
177
 
168
178
  logRegular(`[ACB] Replacing in output...`);
169
179
  results.forEach(({inputPath, outputPath, url, content}) => {
package/README.md CHANGED
@@ -15,8 +15,9 @@ Into...
15
15
  ## How-to
16
16
  ### Getting started
17
17
  1. Install the plugin
18
+ - pnpm: `pnpm install eleventy-auto-cache-buster`
18
19
  - Yarn: `yarn add -D eleventy-auto-cache-buster`
19
- - Npm: `npm install --save-dev eleventy-auto-cache-buster`
20
+ - npm: `npm install --save-dev eleventy-auto-cache-buster`
20
21
  2. Enable the plugin
21
22
  ```js
22
23
  // .eleventy.js
@@ -54,6 +55,20 @@ module.exports = function (eleventyConfig) {
54
55
  }
55
56
  ```
56
57
 
58
+ ### Clone locally/dev
59
+ This requires git & Node.js to be installed
60
+ ```bash
61
+ # Clone repository & enter directory
62
+ git clone https://github.com/Denperidge/eleventy-auto-cache-buster.git
63
+ cd eleventy-auto-cache-buster
64
+
65
+ # Prepare correct pnpm version
66
+ corepack enable
67
+ # Install dependencies
68
+ pnpm install
69
+ # Run tests
70
+ pnpm test
71
+ ```
57
72
 
58
73
  ## License
59
74
  This project is licensed under the [MIT License](LICENSE).
package/package.json CHANGED
@@ -1,18 +1,22 @@
1
1
  {
2
2
  "name": "eleventy-auto-cache-buster",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Busts cache using ?v= with minimal configuration!",
5
5
  "main": "11tyAutoCacheBuster.js",
6
6
  "repository": "https://github.com/Denperidge/eleventy-auto-cache-buster.git",
7
7
  "author": "Denperidge",
8
8
  "license": "MIT",
9
+ "engines": {
10
+ "node": ">=20"
11
+ },
12
+ "packageManager": "pnpm@10.32.1+sha256.9b943b94bc8f55efb993aad8e44b538e6b091e60a9e4a944dcde869855f233e3",
9
13
  "scripts": {
10
- "start": "pushd tests && RUNASYNC=0 USESERVE=1 HASHTRUNCATE=16 eleventy && popd",
14
+ "start": "pushd tests/scenarios/8-sync@3 && eleventy && popd",
11
15
  "test": "ava tests/test.mjs --timeout=30s"
12
16
  },
13
17
  "dependencies": {
14
- "glob": "^13.0.6",
15
- "regexp.escape": "^2.0.1"
18
+ "escape-string-regexp": "^5.0.0",
19
+ "glob": "^13.0.6"
16
20
  },
17
21
  "devDependencies": {
18
22
  "@11ty/eleventy": "^3.1.2",
@@ -0,0 +1,22 @@
1
+ # Minimum release age
2
+ # https://yarnpkg.com/configuration/yarnrc#npmMinimalAgeGate
3
+ minimumReleaseAge: 4320 # in minutes
4
+ minimumReleaseAgeExclude:
5
+ - undici@7.24.2
6
+
7
+ # Block install scripts
8
+ # https://pnpm.io/settings#strictdepbuilds
9
+ strictDepBuilds: true
10
+
11
+ # Block git repo/tarball sources for indirect dependencies
12
+ # https://pnpm.io/settings#blockexoticsubdeps
13
+ blockExoticSubdeps: true
14
+
15
+ # Don't install newer versions if security measures decreased
16
+ # https://pnpm.io/settings#trustpolicy
17
+ trustPolicy: no-downgrade
18
+
19
+ # Disable hoisting
20
+ # https://pnpm.io/blog/2020/10/17/node-modules-configuration-options-with-pnpm#a-strict-traditional-modules-directory
21
+ hoist: false
22
+