@patternslib/dev 4.2.0 → 4.2.1
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/CHANGES.md +16 -0
- package/package.json +9 -9
- package/src/webpack-assets.test.js +92 -0
- package/webpack/webpack.config.js +16 -1
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.2.1](https://github.com/Patternslib/dev/compare/4.2.0...4.2.1) (2026-09-18)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Correct SVG file references. ([987adc3](https://github.com/Patternslib/dev/commit/987adc305acd8b59b2870e3aa3034391274b0d0e))
|
|
8
|
+
|
|
9
|
+
SVG files which are referenced in CSS/JS URL directives are now emitted
|
|
10
|
+
as separate files which can be imported via the URL directive. Raw SVG
|
|
11
|
+
imports in JavaScript files are still included as source.
|
|
12
|
+
|
|
13
|
+
This fixes an issue where SVG references in CSS files were broken.
|
|
14
|
+
|
|
15
|
+
### Maintenance
|
|
16
|
+
|
|
17
|
+
- Upgrade dependencies. ([ae2ba0f](https://github.com/Patternslib/dev/commit/ae2ba0f973042e16546becc4c0131226541e6d5b))
|
|
18
|
+
|
|
3
19
|
## [4.2.0](https://github.com/Patternslib/dev/compare/4.1.0...4.2.0) (2026-09-17)
|
|
4
20
|
|
|
5
21
|
### Features
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternslib/dev",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Development base files for working with Patternslib and add-ons.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@babel/core": "^8.0.
|
|
8
|
-
"@babel/preset-env": "^8.0.
|
|
7
|
+
"@babel/core": "^8.0.6",
|
|
8
|
+
"@babel/preset-env": "^8.0.6",
|
|
9
9
|
"@commitlint/cli": "^21.2.2",
|
|
10
10
|
"@commitlint/config-conventional": "^21.2.2",
|
|
11
11
|
"@eslint/js": "^10.0.1",
|
|
12
12
|
"@release-it/conventional-changelog": "^12.0.2",
|
|
13
13
|
"babel-loader": "^10.1.1",
|
|
14
14
|
"css-loader": "^7.1.5",
|
|
15
|
-
"eslint": "^10.
|
|
15
|
+
"eslint": "^10.11.0",
|
|
16
16
|
"eslint-config-prettier": "^10.1.8",
|
|
17
17
|
"globals": "^17.12.0",
|
|
18
18
|
"identity-obj-proxy": "^3.0.0",
|
|
19
|
-
"jest": "^30.5.
|
|
20
|
-
"jest-environment-jsdom": "^30.5.
|
|
19
|
+
"jest": "^30.5.2",
|
|
20
|
+
"jest-environment-jsdom": "^30.5.2",
|
|
21
21
|
"jest-watch-typeahead": "^3.0.1",
|
|
22
|
-
"prettier": "^3.9.
|
|
22
|
+
"prettier": "^3.9.8",
|
|
23
23
|
"regenerator-runtime": "^0.14.1",
|
|
24
|
-
"release-it": "^21.0
|
|
24
|
+
"release-it": "^21.1.0",
|
|
25
25
|
"sass": "^1.104.1",
|
|
26
26
|
"sass-loader": "^17.0.1",
|
|
27
27
|
"style-loader": "^4.0.0",
|
|
28
28
|
"terser-webpack-plugin": "^5.6.1",
|
|
29
29
|
"timezone-mock": "^1.4.3",
|
|
30
|
-
"webpack": "^5.111.
|
|
30
|
+
"webpack": "^5.111.1",
|
|
31
31
|
"webpack-bundle-analyzer": "^5.3.3",
|
|
32
32
|
"webpack-cli": "^7.2.3",
|
|
33
33
|
"webpack-dev-server": "^6.0.0",
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const { execFileSync } = require("node:child_process");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const os = require("node:os");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
|
|
6
|
+
it("builds SVG URL dependencies as files while preserving raw SVG imports", () => {
|
|
7
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "patternslib-assets-"));
|
|
8
|
+
const svg = '<svg xmlns="http://www.w3.org/2000/svg"><path fill="#fff"/></svg>';
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
fs.writeFileSync(path.join(directory, "icon.svg"), svg);
|
|
12
|
+
fs.writeFileSync(
|
|
13
|
+
path.join(directory, "style.css"),
|
|
14
|
+
'.icon { background-image: url("./icon.svg"); }',
|
|
15
|
+
);
|
|
16
|
+
// .mjs avoids unrelated Babel processing of this small fixture.
|
|
17
|
+
fs.writeFileSync(
|
|
18
|
+
path.join(directory, "entry.mjs"),
|
|
19
|
+
`import svg from "./icon.svg";
|
|
20
|
+
import css from "./style.css";
|
|
21
|
+
export { svg };
|
|
22
|
+
export const styles = css.toString();
|
|
23
|
+
export const url = new URL("./icon.svg", import.meta.url).href;`,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Run Webpack and the generated bundle in Node, outside Jest's module
|
|
27
|
+
// transforms and CSS/SVG mocks. No browser is needed for this build.
|
|
28
|
+
const result = JSON.parse(
|
|
29
|
+
execFileSync(
|
|
30
|
+
process.execPath,
|
|
31
|
+
[
|
|
32
|
+
"-e",
|
|
33
|
+
`const path = require("node:path");
|
|
34
|
+
const webpack = require("webpack");
|
|
35
|
+
const directory = process.argv[1];
|
|
36
|
+
const config = require("./webpack/webpack.config").config({
|
|
37
|
+
config: {
|
|
38
|
+
mode: "development",
|
|
39
|
+
target: "node",
|
|
40
|
+
context: directory,
|
|
41
|
+
entry: "./entry.mjs",
|
|
42
|
+
devtool: false,
|
|
43
|
+
optimization: { minimize: false },
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
config.output = {
|
|
47
|
+
...config.output,
|
|
48
|
+
path: path.join(directory, "dist"),
|
|
49
|
+
filename: "bundle.cjs",
|
|
50
|
+
publicPath: "https://example.test/assets/",
|
|
51
|
+
library: { type: "commonjs2" },
|
|
52
|
+
};
|
|
53
|
+
config.resolveLoader = {
|
|
54
|
+
modules: [path.resolve("node_modules")],
|
|
55
|
+
};
|
|
56
|
+
// Export the CSS string instead of injecting a style tag.
|
|
57
|
+
const cssRule = config.module.rules.find(rule => rule.test.test("style.css"));
|
|
58
|
+
cssRule.use = cssRule.use.filter(item => item.loader !== "style-loader");
|
|
59
|
+
const compiler = webpack(config);
|
|
60
|
+
compiler.run((error, stats) => {
|
|
61
|
+
compiler.close(closeError => {
|
|
62
|
+
if (error || closeError) throw error || closeError;
|
|
63
|
+
if (stats.hasErrors()) throw new Error(stats.toString());
|
|
64
|
+
const result = require(path.join(directory, "dist/bundle.cjs"));
|
|
65
|
+
process.stdout.write(JSON.stringify(result));
|
|
66
|
+
});
|
|
67
|
+
});`,
|
|
68
|
+
directory,
|
|
69
|
+
],
|
|
70
|
+
{
|
|
71
|
+
cwd: path.resolve(__dirname, ".."),
|
|
72
|
+
env: { ...process.env, NODE_ENV: "test" },
|
|
73
|
+
encoding: "utf8",
|
|
74
|
+
timeout: 30000,
|
|
75
|
+
},
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(result.svg).toBe(svg);
|
|
80
|
+
const files = fs.readdirSync(path.join(directory, "dist"));
|
|
81
|
+
const svgFiles = files.filter((file) => file.endsWith(".svg"));
|
|
82
|
+
expect(svgFiles).toHaveLength(1);
|
|
83
|
+
const assetUrl = `https://example.test/assets/${svgFiles[0]}`;
|
|
84
|
+
expect(result.styles).toContain(`url(${assetUrl})`);
|
|
85
|
+
expect(result.url).toBe(assetUrl);
|
|
86
|
+
expect(fs.readFileSync(path.join(directory, "dist", svgFiles[0]), "utf8")).toBe(
|
|
87
|
+
svg,
|
|
88
|
+
);
|
|
89
|
+
} finally {
|
|
90
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
91
|
+
}
|
|
92
|
+
}, 35000);
|
|
@@ -82,9 +82,24 @@ const config_factory = (env, argv, config, babel_include = [], package_json) =>
|
|
|
82
82
|
],
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
|
-
test:
|
|
85
|
+
test: /\.(?:html|xml)$/i,
|
|
86
86
|
type: "asset/source",
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
test: /\.svg$/i,
|
|
90
|
+
oneOf: [
|
|
91
|
+
{
|
|
92
|
+
// Keep resource imports for CSS url(...) and
|
|
93
|
+
// JavaScript new URL(..., import.meta.url)
|
|
94
|
+
dependency: "url",
|
|
95
|
+
type: "asset/resource",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
// Preserve raw markup for ordinary JavaScript SVG imports.
|
|
99
|
+
type: "asset/source",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
88
103
|
{
|
|
89
104
|
test: /\.(eot|woff|woff2|ttf|png|jpe?g|gif|webp)$/i,
|
|
90
105
|
type: "asset/resource",
|