From 2302cc48be456473b8d460c2909e92db625a6573 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 9 Jan 2024 17:19:50 +0100 Subject: [PATCH 01/13] Add config.includePaths and strip includePaths from file.js output paths --- package/config.js | 2 ++ package/index.d.ts | 1 + package/rules/__tests__/babel.js | 2 +- package/rules/__tests__/esbuild.js | 2 +- package/rules/__tests__/file.js | 17 +++++++++++++++++ package/rules/__tests__/swc.js | 2 +- package/rules/file.js | 15 ++++++++++----- package/rules/jscommon.js | 7 ++----- package/rules/less.js | 11 +++++------ package/rules/stylus.js | 9 ++------- 10 files changed, 42 insertions(+), 26 deletions(-) diff --git a/package/config.js b/package/config.js index 1db414c9a..e0327d63e 100644 --- a/package/config.js +++ b/package/config.js @@ -53,4 +53,6 @@ if (config.manifest_path) { config.manifestPath = resolve(config.outputPath, 'manifest.json') } +config.includePaths = [config.source_path, ...config.additional_paths] + module.exports = config diff --git a/package/index.d.ts b/package/index.d.ts index ff6a446d0..bea4fe809 100644 --- a/package/index.d.ts +++ b/package/index.d.ts @@ -22,6 +22,7 @@ declare module 'shakapacker' { publicPath: string publicPathWithoutCDN: string manifestPath: string + includePaths: string[] } export interface Env { diff --git a/package/rules/__tests__/babel.js b/package/rules/__tests__/babel.js index 26961034d..bd0aa2ecc 100644 --- a/package/rules/__tests__/babel.js +++ b/package/rules/__tests__/babel.js @@ -12,7 +12,7 @@ jest.mock("../../config", () => { const original = jest.requireActual("../../config"); return { ...original, - additional_paths: [...original.additional_paths, "node_modules/included"], + includePaths: [...original.includePaths, "node_modules/included"] }; }); diff --git a/package/rules/__tests__/esbuild.js b/package/rules/__tests__/esbuild.js index 33fc407e4..a5b2b73f9 100644 --- a/package/rules/__tests__/esbuild.js +++ b/package/rules/__tests__/esbuild.js @@ -13,7 +13,7 @@ jest.mock("../../config", () => { return { ...original, webpack_loader: "esbuild", - additional_paths: [...original.additional_paths, "node_modules/included"], + includePaths: [...original.includePaths, "node_modules/included"] }; }); diff --git a/package/rules/__tests__/file.js b/package/rules/__tests__/file.js index 88a8f245a..67b138069 100644 --- a/package/rules/__tests__/file.js +++ b/package/rules/__tests__/file.js @@ -1,5 +1,13 @@ const file = require('../file') +jest.mock("../../config", () => { + const original = jest.requireActual("../../config"); + return { + ...original, + includePaths: [...original.includePaths, 'app/assets'] + }; +}); + describe('file', () => { test('test expected file types', () => { const types = [ @@ -59,4 +67,13 @@ describe('file', () => { 'static/images/nested/deeply/[name]-[hash][ext][query]' ); }); + + test('correct generated output path is returned for all include paths', () => { + const pathData = { + filename: 'app/assets/images/image.svg', + }; + expect(file.generator.filename(pathData)).toEqual( + 'static/images/[name]-[hash][ext][query]' + ); + }); }) diff --git a/package/rules/__tests__/swc.js b/package/rules/__tests__/swc.js index c9448bae6..6da9fa496 100644 --- a/package/rules/__tests__/swc.js +++ b/package/rules/__tests__/swc.js @@ -12,7 +12,7 @@ jest.mock("../../config", () => { return { ...original, webpack_loader: "swc", - additional_paths: [...original.additional_paths, "node_modules/included"], + includePaths: [...original.includePaths, "node_modules/included"], }; }); diff --git a/package/rules/file.js b/package/rules/file.js index 6c5fdde01..9bd7ace40 100644 --- a/package/rules/file.js +++ b/package/rules/file.js @@ -1,5 +1,7 @@ const { dirname } = require('path') -const { source_path: sourcePath } = require('../config') +const { includePaths } = require('../config') + +console.log(includePaths); module.exports = { test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/, @@ -7,12 +9,15 @@ module.exports = { type: 'asset/resource', generator: { filename: (pathData) => { - const folders = dirname(pathData.filename) - .replace(`${sourcePath}`, '') - .split('/') - .filter(Boolean) + let path = dirname(pathData.filename) + + for (const includePath of includePaths) { + path = path.replace(`${includePath}`, '') + } + const folders = path.split('/').filter(Boolean) const foldersWithStatic = ['static', ...folders].join('/') + return `${foldersWithStatic}/[name]-[hash][ext][query]` } } diff --git a/package/rules/jscommon.js b/package/rules/jscommon.js index 69a777cd9..6e182c457 100644 --- a/package/rules/jscommon.js +++ b/package/rules/jscommon.js @@ -1,11 +1,8 @@ const { resolve } = require('path') const { realpathSync } = require('fs') -const { - source_path: sourcePath, - additional_paths: additionalPaths -} = require('../config') +const { includePaths } = require('../config') -const inclusions = [sourcePath, ...additionalPaths].map(p => { +const inclusions = includePaths.map(p => { try { return realpathSync(p) } catch (e) { diff --git a/package/rules/less.js b/package/rules/less.js index 5eec5e71b..24ad0fe4e 100644 --- a/package/rules/less.js +++ b/package/rules/less.js @@ -1,11 +1,7 @@ const path = require('path') const { canProcess } = require('../utils/helpers') const getStyleRule = require('../utils/get_style_rule') - -const { - additional_paths: paths, - source_path: sourcePath -} = require('../config') +const { includePaths } = require('../config') module.exports = canProcess('less-loader', (resolvedPath) => getStyleRule(/\.(less)(\.erb)?$/i, [ @@ -13,7 +9,10 @@ module.exports = canProcess('less-loader', (resolvedPath) => loader: resolvedPath, options: { lessOptions: { - paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths] + paths: [ + path.resolve(__dirname, 'node_modules'), + ...includePaths + ] }, sourceMap: true } diff --git a/package/rules/stylus.js b/package/rules/stylus.js index 807a07799..a4e41a1ee 100644 --- a/package/rules/stylus.js +++ b/package/rules/stylus.js @@ -1,11 +1,7 @@ const path = require('path') const { canProcess } = require('../utils/helpers') const getStyleRule = require('../utils/get_style_rule') - -const { - additional_paths: paths, - source_path: sourcePath -} = require('../config') +const { includePaths } = require('../config') module.exports = canProcess('stylus-loader', (resolvedPath) => getStyleRule(/\.(styl(us)?)(\.erb)?$/i, [ @@ -15,8 +11,7 @@ module.exports = canProcess('stylus-loader', (resolvedPath) => stylusOptions: { include: [ path.resolve(__dirname, 'node_modules'), - sourcePath, - ...paths + ...includePaths ] }, sourceMap: true From 70d9dc01641c129a8919905748a5366ce0712186 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 9 Jan 2024 17:55:44 +0100 Subject: [PATCH 02/13] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 260fdccc8..ce1523416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Changes since the last non-beta release. _Please add entries here for your pull requests that are not yet released._ +### Changed +- Just like with the `source_path` the paths in `additional_paths` will now also be stripped from asset paths. [PR 403](https://github.com/shakacode/shakapacker/pull/403) by [paypro-leon](https://github.com/paypro-leon). + ## [v7.2.1] - December 30, 2023 ### Fixed From 70ca3921763c0fa6f0f7e9d19160e3c31dcd7878 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 9 Jan 2024 17:58:35 +0100 Subject: [PATCH 03/13] Refactor code to fix lint issue --- package/rules/file.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package/rules/file.js b/package/rules/file.js index 9bd7ace40..cfcc1c829 100644 --- a/package/rules/file.js +++ b/package/rules/file.js @@ -1,8 +1,6 @@ const { dirname } = require('path') const { includePaths } = require('../config') -console.log(includePaths); - module.exports = { test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/, exclude: /\.(js|mjs|jsx|ts|tsx)$/, @@ -11,9 +9,9 @@ module.exports = { filename: (pathData) => { let path = dirname(pathData.filename) - for (const includePath of includePaths) { + includePaths.forEach((includePath) => { path = path.replace(`${includePath}`, '') - } + }) const folders = path.split('/').filter(Boolean) const foldersWithStatic = ['static', ...folders].join('/') From f907070472691e00af6a9beebc1dd81aaff69a73 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 9 Jan 2024 18:11:24 +0100 Subject: [PATCH 04/13] Make sure to replace only once --- package/rules/file.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package/rules/file.js b/package/rules/file.js index cfcc1c829..8f434da39 100644 --- a/package/rules/file.js +++ b/package/rules/file.js @@ -7,15 +7,15 @@ module.exports = { type: 'asset/resource', generator: { filename: (pathData) => { - let path = dirname(pathData.filename) + const path = dirname(pathData.filename) + const includePath = includePaths.find((includePath) => path.includes(includePath)) - includePaths.forEach((includePath) => { - path = path.replace(`${includePath}`, '') - }) + const folders = path + .replace(`${includePath}`, '') + .split('/') + .filter(Boolean) - const folders = path.split('/').filter(Boolean) const foldersWithStatic = ['static', ...folders].join('/') - return `${foldersWithStatic}/[name]-[hash][ext][query]` } } From 3364cd5c1162f93d4678dbad1546f52849f801a8 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 9 Jan 2024 18:18:13 +0100 Subject: [PATCH 05/13] Change variable name --- package/rules/file.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/rules/file.js b/package/rules/file.js index 8f434da39..bd537dd89 100644 --- a/package/rules/file.js +++ b/package/rules/file.js @@ -8,10 +8,10 @@ module.exports = { generator: { filename: (pathData) => { const path = dirname(pathData.filename) - const includePath = includePaths.find((includePath) => path.includes(includePath)) + const selectedIncludePath = includePaths.find((includePath) => path.includes(includePath)) const folders = path - .replace(`${includePath}`, '') + .replace(`${selectedIncludePath}`, '') .split('/') .filter(Boolean) From 83078588d40531dc03b60b88834d2956cea44d6d Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Fri, 19 Jan 2024 16:41:22 +0100 Subject: [PATCH 06/13] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 485198fa2..2ae38417d 100644 --- a/README.md +++ b/README.md @@ -880,6 +880,10 @@ import 'stylesheets/main' import 'images/rails.png' ``` +Assets put in these folders will have their directory stripped just like with the `source_path`. For example: + +A file in `app/assets/images/image.svg` with `additional_paths: ['app/assets']` would result in `static/images/image.svg` + **Note:** Please be careful when adding paths here otherwise it will make the compilation slow, consider adding specific paths instead of the whole parent directory if you just need to reference one or two modules **Also note:** While importing assets living outside your `source_path` defined in shakapacker.yml (like, for instance, assets under `app/assets`) from within your packs using _relative_ paths like `import '../../assets/javascripts/file.js'` will work in development, Shakapacker won't recompile the bundle in production unless a file that lives in one of it's watched paths has changed (check out `Shakapacker::MtimeStrategy#latest_modified_timestamp` or `Shakapacker::DigestStrategy#watched_files_digest` depending on strategy configured by `compiler_strategy` option in `shakapacker.yml`). That's why you'd need to add `app/assets` to the additional_paths as stated above and use `import 'javascripts/file.js'` instead. From 953c2d265f7f3c54261205e91aaa98478ea7ac3e Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Fri, 19 Jan 2024 16:42:57 +0100 Subject: [PATCH 07/13] Grammer change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ae38417d..7eb75ee00 100644 --- a/README.md +++ b/README.md @@ -882,7 +882,7 @@ import 'images/rails.png' Assets put in these folders will have their directory stripped just like with the `source_path`. For example: -A file in `app/assets/images/image.svg` with `additional_paths: ['app/assets']` would result in `static/images/image.svg` +A file in `app/assets/images/image.svg` with `additional_paths: ['app/assets']` will result in `static/images/image.svg` **Note:** Please be careful when adding paths here otherwise it will make the compilation slow, consider adding specific paths instead of the whole parent directory if you just need to reference one or two modules From f369e21a52d5199f984408a451eb4ba7fb64fd55 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Mon, 22 Jan 2024 11:24:12 +0100 Subject: [PATCH 08/13] Revert includePath change and make stripping additional_paths opt-in --- README.md | 4 +++- package/config.js | 2 -- package/index.d.ts | 1 - package/rules/__tests__/babel.js | 2 +- package/rules/__tests__/esbuild.js | 2 +- package/rules/__tests__/file.js | 17 +++++++++++++++-- package/rules/__tests__/swc.js | 2 +- package/rules/file.js | 11 ++++++++--- package/rules/jscommon.js | 7 +++++-- package/rules/less.js | 8 ++++++-- package/rules/stylus.js | 8 ++++++-- 11 files changed, 46 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7eb75ee00..6f0942392 100644 --- a/README.md +++ b/README.md @@ -880,7 +880,9 @@ import 'stylesheets/main' import 'images/rails.png' ``` -Assets put in these folders will have their directory stripped just like with the `source_path`. For example: +There is experimental support for stripping these paths from the asset paths by setting the env variable `SHAKAPACKER_STRIP_ADDITIONAL_PATHS=true`. In Shakapacker version 8 this will be the default behavior. + +Example: A file in `app/assets/images/image.svg` with `additional_paths: ['app/assets']` will result in `static/images/image.svg` diff --git a/package/config.js b/package/config.js index e0327d63e..1db414c9a 100644 --- a/package/config.js +++ b/package/config.js @@ -53,6 +53,4 @@ if (config.manifest_path) { config.manifestPath = resolve(config.outputPath, 'manifest.json') } -config.includePaths = [config.source_path, ...config.additional_paths] - module.exports = config diff --git a/package/index.d.ts b/package/index.d.ts index bea4fe809..ff6a446d0 100644 --- a/package/index.d.ts +++ b/package/index.d.ts @@ -22,7 +22,6 @@ declare module 'shakapacker' { publicPath: string publicPathWithoutCDN: string manifestPath: string - includePaths: string[] } export interface Env { diff --git a/package/rules/__tests__/babel.js b/package/rules/__tests__/babel.js index bd0aa2ecc..26961034d 100644 --- a/package/rules/__tests__/babel.js +++ b/package/rules/__tests__/babel.js @@ -12,7 +12,7 @@ jest.mock("../../config", () => { const original = jest.requireActual("../../config"); return { ...original, - includePaths: [...original.includePaths, "node_modules/included"] + additional_paths: [...original.additional_paths, "node_modules/included"], }; }); diff --git a/package/rules/__tests__/esbuild.js b/package/rules/__tests__/esbuild.js index a5b2b73f9..33fc407e4 100644 --- a/package/rules/__tests__/esbuild.js +++ b/package/rules/__tests__/esbuild.js @@ -13,7 +13,7 @@ jest.mock("../../config", () => { return { ...original, webpack_loader: "esbuild", - includePaths: [...original.includePaths, "node_modules/included"] + additional_paths: [...original.additional_paths, "node_modules/included"], }; }); diff --git a/package/rules/__tests__/file.js b/package/rules/__tests__/file.js index 67b138069..1950fb903 100644 --- a/package/rules/__tests__/file.js +++ b/package/rules/__tests__/file.js @@ -4,7 +4,7 @@ jest.mock("../../config", () => { const original = jest.requireActual("../../config"); return { ...original, - includePaths: [...original.includePaths, 'app/assets'] + additional_paths: [...original.additional_paths, "app/assets"], }; }); @@ -68,10 +68,23 @@ describe('file', () => { ); }); - test('correct generated output path is returned for all include paths', () => { + test('correct generated output path is returned for additional_paths', () => { const pathData = { filename: 'app/assets/images/image.svg', }; + + expect(file.generator.filename(pathData)).toEqual( + 'static/app/assets/images/[name]-[hash][ext][query]' + ); + }); + + test('correct generated output path is returned for additional_paths when opting in', () => { + const pathData = { + filename: 'app/assets/images/image.svg', + }; + + process.env.SHAKAPACKER_STRIP_ADDITIONAL_PATHS = 'true'; + expect(file.generator.filename(pathData)).toEqual( 'static/images/[name]-[hash][ext][query]' ); diff --git a/package/rules/__tests__/swc.js b/package/rules/__tests__/swc.js index 6da9fa496..c9448bae6 100644 --- a/package/rules/__tests__/swc.js +++ b/package/rules/__tests__/swc.js @@ -12,7 +12,7 @@ jest.mock("../../config", () => { return { ...original, webpack_loader: "swc", - includePaths: [...original.includePaths, "node_modules/included"], + additional_paths: [...original.additional_paths, "node_modules/included"], }; }); diff --git a/package/rules/file.js b/package/rules/file.js index bd537dd89..20d2a6404 100644 --- a/package/rules/file.js +++ b/package/rules/file.js @@ -1,5 +1,8 @@ const { dirname } = require('path') -const { includePaths } = require('../config') +const { + additional_paths: additionalPaths, + source_path: sourcePath +} = require('../config') module.exports = { test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/, @@ -8,10 +11,12 @@ module.exports = { generator: { filename: (pathData) => { const path = dirname(pathData.filename) - const selectedIncludePath = includePaths.find((includePath) => path.includes(includePath)) + const stripPaths = process.env.SHAKAPACKER_STRIP_ADDITIONAL_PATHS === 'true' ? [...additionalPaths, sourcePath] : [sourcePath] + + const selectedStripPath = stripPaths.find((includePath) => path.includes(includePath)) const folders = path - .replace(`${selectedIncludePath}`, '') + .replace(`${selectedStripPath}`, '') .split('/') .filter(Boolean) diff --git a/package/rules/jscommon.js b/package/rules/jscommon.js index 6e182c457..69a777cd9 100644 --- a/package/rules/jscommon.js +++ b/package/rules/jscommon.js @@ -1,8 +1,11 @@ const { resolve } = require('path') const { realpathSync } = require('fs') -const { includePaths } = require('../config') +const { + source_path: sourcePath, + additional_paths: additionalPaths +} = require('../config') -const inclusions = includePaths.map(p => { +const inclusions = [sourcePath, ...additionalPaths].map(p => { try { return realpathSync(p) } catch (e) { diff --git a/package/rules/less.js b/package/rules/less.js index 24ad0fe4e..507b7f1f7 100644 --- a/package/rules/less.js +++ b/package/rules/less.js @@ -1,7 +1,10 @@ const path = require('path') const { canProcess } = require('../utils/helpers') const getStyleRule = require('../utils/get_style_rule') -const { includePaths } = require('../config') +const { + additional_paths: paths, + source_path: sourcePath +} = require('../config') module.exports = canProcess('less-loader', (resolvedPath) => getStyleRule(/\.(less)(\.erb)?$/i, [ @@ -11,7 +14,8 @@ module.exports = canProcess('less-loader', (resolvedPath) => lessOptions: { paths: [ path.resolve(__dirname, 'node_modules'), - ...includePaths + sourcePath, + ...paths ] }, sourceMap: true diff --git a/package/rules/stylus.js b/package/rules/stylus.js index a4e41a1ee..8d2528f6d 100644 --- a/package/rules/stylus.js +++ b/package/rules/stylus.js @@ -1,7 +1,10 @@ const path = require('path') const { canProcess } = require('../utils/helpers') const getStyleRule = require('../utils/get_style_rule') -const { includePaths } = require('../config') +const { + additional_paths: paths, + source_path: sourcePath +} = require('../config') module.exports = canProcess('stylus-loader', (resolvedPath) => getStyleRule(/\.(styl(us)?)(\.erb)?$/i, [ @@ -11,7 +14,8 @@ module.exports = canProcess('stylus-loader', (resolvedPath) => stylusOptions: { include: [ path.resolve(__dirname, 'node_modules'), - ...includePaths + sourcePath, + ...paths ] }, sourceMap: true From a3493c3492140cd7a9857325b9b59361ff93b453 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Mon, 22 Jan 2024 11:28:22 +0100 Subject: [PATCH 09/13] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce1523416..6f089c0e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,8 @@ Changes since the last non-beta release. _Please add entries here for your pull requests that are not yet released._ -### Changed -- Just like with the `source_path` the paths in `additional_paths` will now also be stripped from asset paths. [PR 403](https://github.com/shakacode/shakapacker/pull/403) by [paypro-leon](https://github.com/paypro-leon). +### Added +- Opt-in support for stripping `additional_paths` from the asset paths just like with the `source_path`. This will be the default behavior in version 8. [PR 403](https://github.com/shakacode/shakapacker/pull/403) by [paypro-leon](https://github.com/paypro-leon). ## [v7.2.1] - December 30, 2023 From bd2dd2ec160977cbf7043d220056bc0a9a071add Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Mon, 22 Jan 2024 11:47:10 +0100 Subject: [PATCH 10/13] Revert some more changes --- package/rules/less.js | 1 + package/rules/stylus.js | 1 + 2 files changed, 2 insertions(+) diff --git a/package/rules/less.js b/package/rules/less.js index 507b7f1f7..088e13288 100644 --- a/package/rules/less.js +++ b/package/rules/less.js @@ -1,6 +1,7 @@ const path = require('path') const { canProcess } = require('../utils/helpers') const getStyleRule = require('../utils/get_style_rule') + const { additional_paths: paths, source_path: sourcePath diff --git a/package/rules/stylus.js b/package/rules/stylus.js index 8d2528f6d..807a07799 100644 --- a/package/rules/stylus.js +++ b/package/rules/stylus.js @@ -1,6 +1,7 @@ const path = require('path') const { canProcess } = require('../utils/helpers') const getStyleRule = require('../utils/get_style_rule') + const { additional_paths: paths, source_path: sourcePath From 5953225760822b4add9111dabc7e06d6ae7f750b Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 23 Jan 2024 10:55:39 +0100 Subject: [PATCH 11/13] Revert changes --- package/rules/less.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/package/rules/less.js b/package/rules/less.js index 088e13288..5eec5e71b 100644 --- a/package/rules/less.js +++ b/package/rules/less.js @@ -13,11 +13,7 @@ module.exports = canProcess('less-loader', (resolvedPath) => loader: resolvedPath, options: { lessOptions: { - paths: [ - path.resolve(__dirname, 'node_modules'), - sourcePath, - ...paths - ] + paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths] }, sourceMap: true } From 8fd4ae64db42e1382214d5287b3f9841f53c9900 Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 26 Mar 2024 10:53:56 +0100 Subject: [PATCH 12/13] Remove opt-in check --- package/rules/__tests__/file.js | 12 ------------ package/rules/file.js | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/package/rules/__tests__/file.js b/package/rules/__tests__/file.js index 1950fb903..60e7905b5 100644 --- a/package/rules/__tests__/file.js +++ b/package/rules/__tests__/file.js @@ -73,18 +73,6 @@ describe('file', () => { filename: 'app/assets/images/image.svg', }; - expect(file.generator.filename(pathData)).toEqual( - 'static/app/assets/images/[name]-[hash][ext][query]' - ); - }); - - test('correct generated output path is returned for additional_paths when opting in', () => { - const pathData = { - filename: 'app/assets/images/image.svg', - }; - - process.env.SHAKAPACKER_STRIP_ADDITIONAL_PATHS = 'true'; - expect(file.generator.filename(pathData)).toEqual( 'static/images/[name]-[hash][ext][query]' ); diff --git a/package/rules/file.js b/package/rules/file.js index 20d2a6404..2ab1155ea 100644 --- a/package/rules/file.js +++ b/package/rules/file.js @@ -11,7 +11,7 @@ module.exports = { generator: { filename: (pathData) => { const path = dirname(pathData.filename) - const stripPaths = process.env.SHAKAPACKER_STRIP_ADDITIONAL_PATHS === 'true' ? [...additionalPaths, sourcePath] : [sourcePath] + const stripPaths = [...additionalPaths, sourcePath] const selectedStripPath = stripPaths.find((includePath) => path.includes(includePath)) From d726a7b8a8be744c9b7839747edbd1e8fd1f35db Mon Sep 17 00:00:00 2001 From: Leon van der Velde Date: Tue, 26 Mar 2024 11:09:11 +0100 Subject: [PATCH 13/13] Update README and CHANGELOG --- CHANGELOG.md | 5 ++--- README.md | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8134a8ffa..50ad96e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ Changes since the last non-beta release. - Enable `ensure_consistent_versioning` by default [PR 447](https://github.com/shakacode/shakapacker/pull/447) by [G-Rath](https://github.com/g-rath). +- Asset files put in `additional_paths` will have their path stripped just like with the `source_path`. [PR 403](https://github.com/shakacode/shakapacker/pull/403) by [paypro-leon](https://github.com/paypro-leon). + ### Added - Emit warnings instead of errors when compilation is success but stderr is not empty. [PR 416](https://github.com/shakacode/shakapacker/pull/416) by [n-rodriguez](https://github.com/n-rodriguez). - Allow `webpack-dev-server` v5. [PR 418](https://github.com/shakacode/shakapacker/pull/418) by [G-Rath](https://github.com/g-rath) @@ -51,9 +53,6 @@ Changes since the last non-beta release. ### Added - Allow `compression-webpack-plugin` v11. [PR 406](https://github.com/shakacode/shakapacker/pull/406) by [tagliala](https://github.com/tagliala). -### Added -- Opt-in support for stripping `additional_paths` from the asset paths just like with the `source_path`. This will be the default behavior in version 8. [PR 403](https://github.com/shakacode/shakapacker/pull/403) by [paypro-leon](https://github.com/paypro-leon). - ## [v7.2.1] - December 30, 2023 ### Fixed diff --git a/README.md b/README.md index a4a463e44..3f7eb11ac 100644 --- a/README.md +++ b/README.md @@ -899,7 +899,7 @@ import 'stylesheets/main' import 'images/rails.png' ``` -There is experimental support for stripping these paths from the asset paths by setting the env variable `SHAKAPACKER_STRIP_ADDITIONAL_PATHS=true`. In Shakapacker version 8 this will be the default behavior. +Assets put in these folders will also have their path stripped just like with the `source_path`. Example: