From 8034e17215423587b518fad1d772567ea6e59f07 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 19 Mar 2019 15:59:02 +0000 Subject: [PATCH 1/3] chore(na): change default cache directory --- README.md | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4486868..aced90b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ module.exports = { | :-------------------: | :----------------------------------------------: | :---------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **`cacheContext`** | `{String}` | `undefined` | Allows you to override the default cache context in order to generate the cache relatively to a path. By default it will use absolute paths | | **`cacheKey`** | `{Function(options, request) -> {String}}` | `undefined` | Allows you to override default cache key generator | -| **`cacheDirectory`** | `{String}` | `path.resolve('.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) | +| **`cacheDirectory`** | `{String}` | `path.resolve('./node_modules/.cache/.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) | | **`cacheIdentifier`** | `{String}` | `cache-loader:{version} {process.env.NODE_ENV}` | Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders (used for default read/write implementation) | | **`write`** | `{Function(cacheKey, data, callback) -> {void}}` | `undefined` | Allows you to override default write cache data to file (e.g. Redis, memcached) | | **`read`** | `{Function(cacheKey, callback) -> {void}}` | `undefined` | Allows you to override default read cache data from file | diff --git a/src/index.js b/src/index.js index 8de46e9..45809d6 100644 --- a/src/index.js +++ b/src/index.js @@ -19,7 +19,7 @@ const schema = require('./options.json'); const defaults = { cacheContext: '', - cacheDirectory: path.resolve('.cache-loader'), + cacheDirectory: path.resolve('./node_modules/.cache/.cache-loader'), cacheIdentifier: `cache-loader:${pkg.version} ${env}`, cacheKey, read, From 03c22f90ecd2fdf763b80a6aaafac439a3d7668f Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 19 Mar 2019 17:13:46 +0000 Subject: [PATCH 2/3] refactor(na): use find-cache-dir to found the cache directory --- README.md | 2 +- package-lock.json | 108 +++++++++++++++++++++++++++++++++++++++------- package.json | 1 + src/index.js | 4 +- 4 files changed, 97 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index aced90b..4607465 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ module.exports = { | :-------------------: | :----------------------------------------------: | :---------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **`cacheContext`** | `{String}` | `undefined` | Allows you to override the default cache context in order to generate the cache relatively to a path. By default it will use absolute paths | | **`cacheKey`** | `{Function(options, request) -> {String}}` | `undefined` | Allows you to override default cache key generator | -| **`cacheDirectory`** | `{String}` | `path.resolve('./node_modules/.cache/.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) | +| **`cacheDirectory`** | `{String}` | `findCacheDir({ name: 'cache-loader' }) or os.tmpdir()` | Provide a cache directory where cache items should be stored (used for default read/write implementation) | | **`cacheIdentifier`** | `{String}` | `cache-loader:{version} {process.env.NODE_ENV}` | Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders (used for default read/write implementation) | | **`write`** | `{Function(cacheKey, data, callback) -> {void}}` | `undefined` | Allows you to override default write cache data to file (e.g. Redis, memcached) | | **`read`** | `{Function(cacheKey, callback) -> {void}}` | `undefined` | Allows you to override default read cache data from file | diff --git a/package-lock.json b/package-lock.json index c6ad2be..ccbd2d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1714,6 +1714,19 @@ "loader-utils": "^1.0.2", "mkdirp": "^0.5.1", "util.promisify": "^1.0.0" + }, + "dependencies": { + "find-cache-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-1.0.0.tgz", + "integrity": "sha1-kojj6ePMN0hxfTnq3hfPcfww7m8=", + "dev": true, + "requires": { + "commondir": "^1.0.1", + "make-dir": "^1.0.0", + "pkg-dir": "^2.0.0" + } + } } }, "babel-messages": { @@ -2601,8 +2614,7 @@ "commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", - "dev": true + "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=" }, "compare-func": { "version": "1.3.2", @@ -4672,14 +4684,75 @@ } }, "find-cache-dir": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-1.0.0.tgz", - "integrity": "sha1-kojj6ePMN0hxfTnq3hfPcfww7m8=", - "dev": true, + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz", + "integrity": "sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==", "requires": { "commondir": "^1.0.1", - "make-dir": "^1.0.0", - "pkg-dir": "^2.0.0" + "make-dir": "^2.0.0", + "pkg-dir": "^3.0.0" + }, + "dependencies": { + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "requires": { + "locate-path": "^3.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "make-dir": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", + "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", + "requires": { + "pify": "^4.0.1", + "semver": "^5.6.0" + } + }, + "p-limit": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", + "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "requires": { + "p-limit": "^2.0.0" + } + }, + "p-try": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.1.0.tgz", + "integrity": "sha512-H2RyIJ7+A3rjkwKC2l5GGtU4H1vkxKCAGsWasNVd0Set+6i4znxbWy6/j16YDPJDWxhsgZiKAstMEP8wCdSpjA==" + }, + "pify": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", + "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==" + }, + "pkg-dir": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", + "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", + "requires": { + "find-up": "^3.0.0" + } + } } }, "find-parent-dir": { @@ -4842,7 +4915,8 @@ "version": "2.1.1", "resolved": false, "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -5307,7 +5381,8 @@ "version": "5.1.1", "resolved": false, "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -5371,6 +5446,7 @@ "resolved": false, "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5419,13 +5495,15 @@ "version": "1.0.2", "resolved": false, "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.2", "resolved": false, "integrity": "sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k=", - "dev": true + "dev": true, + "optional": true } } }, @@ -9472,8 +9550,7 @@ "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", - "dev": true + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" }, "path-is-absolute": { "version": "1.0.1", @@ -10385,8 +10462,7 @@ "semver": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", - "dev": true + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==" }, "semver-compare": { "version": "1.0.0", diff --git a/package.json b/package.json index 7dc4127..264b156 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "webpack": "^4.0.0" }, "dependencies": { + "find-cache-dir": "^2.1.0", "loader-utils": "^1.1.0", "mkdirp": "^0.5.1", "neo-async": "^2.6.0", diff --git a/src/index.js b/src/index.js index 45809d6..bab5249 100644 --- a/src/index.js +++ b/src/index.js @@ -2,11 +2,13 @@ import/order */ const fs = require('fs'); +const os = require('os'); const path = require('path'); const normalizePath = require('normalize-path'); const async = require('neo-async'); const crypto = require('crypto'); const mkdirp = require('mkdirp'); +const findCacheDir = require('find-cache-dir'); const { getOptions } = require('loader-utils'); const validateOptions = require('schema-utils'); @@ -19,7 +21,7 @@ const schema = require('./options.json'); const defaults = { cacheContext: '', - cacheDirectory: path.resolve('./node_modules/.cache/.cache-loader'), + cacheDirectory: findCacheDir({ name: 'cache-loader' }) || os.tmpdir(), cacheIdentifier: `cache-loader:${pkg.version} ${env}`, cacheKey, read, From 99ce2e65baf881b197ad38950e55f41f37e97cbc Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Fri, 22 Mar 2019 03:26:56 +0000 Subject: [PATCH 3/3] chore(na): remove error changes --- README.md | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aced90b..4486868 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ module.exports = { | :-------------------: | :----------------------------------------------: | :---------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **`cacheContext`** | `{String}` | `undefined` | Allows you to override the default cache context in order to generate the cache relatively to a path. By default it will use absolute paths | | **`cacheKey`** | `{Function(options, request) -> {String}}` | `undefined` | Allows you to override default cache key generator | -| **`cacheDirectory`** | `{String}` | `path.resolve('./node_modules/.cache/.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) | +| **`cacheDirectory`** | `{String}` | `path.resolve('.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) | | **`cacheIdentifier`** | `{String}` | `cache-loader:{version} {process.env.NODE_ENV}` | Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders (used for default read/write implementation) | | **`write`** | `{Function(cacheKey, data, callback) -> {void}}` | `undefined` | Allows you to override default write cache data to file (e.g. Redis, memcached) | | **`read`** | `{Function(cacheKey, callback) -> {void}}` | `undefined` | Allows you to override default read cache data from file | diff --git a/src/index.js b/src/index.js index 45809d6..8de46e9 100644 --- a/src/index.js +++ b/src/index.js @@ -19,7 +19,7 @@ const schema = require('./options.json'); const defaults = { cacheContext: '', - cacheDirectory: path.resolve('./node_modules/.cache/.cache-loader'), + cacheDirectory: path.resolve('.cache-loader'), cacheIdentifier: `cache-loader:${pkg.version} ${env}`, cacheKey, read,