Skip to content

Commit

Permalink
feat(convert-to-module): convert svgstore, upgrade jest, migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markhughes committed Sep 30, 2024
1 parent b79a581 commit b52bdf6
Show file tree
Hide file tree
Showing 19 changed files with 2,173 additions and 3,235 deletions.
23 changes: 0 additions & 23 deletions jest.config.base.js

This file was deleted.

12 changes: 12 additions & 0 deletions jest.config.base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('jest').Config} */
const config = {
roots: ["<rootDir>/lib", "<rootDir>/tests"],
transform: {
"^.+\\.(js|jsx|mjs)$": "babel-jest",
},
testRegex: "(/tests/.*.(test|spec)).(mjs|jsx?|tsx?)$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node", "mjs"],
coveragePathIgnorePatterns: ["(tests/.*.mock).(jsx?|tsx?)$"],
};

export default config;
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

7 changes: 7 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('jest').Config} */
const config = {
projects: ["<rootDir>/packages/*/jest.config.mjs"],
coverageDirectory: "<rootDir>/coverage/",
};

export default config;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
"@babel/plugin-syntax-import-assertions": "^7.25.6",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.11.1",
"babel-jest": "^27.1.1",
"babel-jest": "^29.7.0",
"clean-css": "5.1.5",
"eslint": "9.11.1",
"eslint-config-standard": "^17.1.0",
"globals": "^15.9.0",
"html-minifier": "4.0.0",
"husky": "^7.0.2",
"jest": "^27.1.1",
"jest": "^29.7.0",
"lerna": "^6.6.2",
"lint-staged": "^11.1.2",
"nx": "^16.2.2",
Expand Down
1 change: 1 addition & 0 deletions packages/svgstore/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { presets: ["@babel/preset-env"] };
1 change: 0 additions & 1 deletion packages/svgstore/babel.config.js

This file was deleted.

7 changes: 0 additions & 7 deletions packages/svgstore/jest.config.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/svgstore/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import base from "../../jest.config.base.mjs";

/** @type {import('jest').Config} */
const config = {
...base,
displayName: "@droppyjs/svgstore",
};

export default config;
21 changes: 10 additions & 11 deletions packages/svgstore/lib/svgstore.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"use strict";

const copyAttributes = require("./utils/copy-attributes");
const loadXml = require("./utils/load-xml");
const removeAttributes = require("./utils/remove-attributes");
const setAttributes = require("./utils/set-attributes");
const svgToSymbol = require("./utils/svg-to-symbol");
import copyAttributes from "./utils/copy-attributes.js";
import loadXml from "./utils/load-xml.js";
import removeAttributes from "./utils/remove-attributes.js";
import setAttributes from "./utils/set-attributes.js";
import svgToSymbol from "./utils/svg-to-symbol.js";

const SELECTOR_SVG = "svg";
const SELECTOR_DEFS = "defs";

const TEMPLATE_SVG = "<svg><defs/></svg>";
const TEMPLATE_DOCTYPE = '<?xml version="1.0" encoding="UTF-8"?>' +
const TEMPLATE_DOCTYPE =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ' +
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';

Expand All @@ -21,10 +22,10 @@ const DEFAULT_OPTIONS = {
svgAttrs: false,
symbolAttrs: false,
copyAttrs: false,
renameDefs: false
renameDefs: false,
};

function svgstore(options) {
export default function svgstore(options) {
const svgstoreOptions = Object.assign({}, DEFAULT_OPTIONS, options);

// <svg>
Expand Down Expand Up @@ -119,8 +120,6 @@ function svgstore(options) {
});

return TEMPLATE_DOCTYPE + clone.xml();
}
},
};
}

module.exports = svgstore;
4 changes: 1 addition & 3 deletions packages/svgstore/lib/utils/copy-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const ALWAYS_COPY_ATTRS = ["viewBox", "aria-labelledby", "role"];

function copyAttributes(a, b, attrs) {
export default function copyAttributes(a, b, attrs) {
const attrsToCopy = ALWAYS_COPY_ATTRS.concat(attrs || []);
const copiedAttrs = Object.create(null);

Expand All @@ -26,5 +26,3 @@ function copyAttributes(a, b, attrs) {

return a;
}

module.exports = copyAttributes;
8 changes: 3 additions & 5 deletions packages/svgstore/lib/utils/load-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

"use strict";

const cheerio = require("cheerio");
import { load } from "cheerio";

function loadXml(text) {
return cheerio.load(text, {
export default function loadXml(text) {
return load(text, {
xmlMode: true,
});
}

module.exports = loadXml;
4 changes: 1 addition & 3 deletions packages/svgstore/lib/utils/remove-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

function removeAttributes(el, attrs) {
export default function removeAttributes(el, attrs) {
let localAttrs = attrs;

if (localAttrs === true) {
Expand All @@ -26,5 +26,3 @@ function removeAttributes(el, attrs) {

return el;
}

module.exports = removeAttributes;
4 changes: 1 addition & 3 deletions packages/svgstore/lib/utils/set-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"use strict";

function setAttributes(el, attrs) {
export default function setAttributes(el, attrs) {
if (!attrs || typeof attrs !== "object") {
return el;
}
Expand All @@ -24,5 +24,3 @@ function setAttributes(el, attrs) {

return el;
}

module.exports = setAttributes;
4 changes: 1 addition & 3 deletions packages/svgstore/lib/utils/svg-to-symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ATTRIBUTE_ID = "id";
* @return {object} symbol The final cheerio-aware object created by cloning the SVG contents
* @see <a href="https://github.com/cheeriojs/cheerio">The Cheerio Project</a>
*/
function svgToSymbol(id, child, _options) {
export default function svgToSymbol(id, child, _options) {
if (_options === void 0) {
_options = {};
}
Expand All @@ -31,5 +31,3 @@ function svgToSymbol(id, child, _options) {

return symbol;
}

module.exports = svgToSymbol;
7 changes: 4 additions & 3 deletions packages/svgstore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"homepage": "https://github.com/droppyjs/droppy#readme",
"license": "MIT",
"main": "lib/svgstore.js",
"type": "module",
"scripts": {
"test": "jest --coverage",
"watch": "chokidar '{lib,test}/**/*.js' -d 1000 -c 'yarn test'"
Expand All @@ -32,10 +33,10 @@
"cheerio": "1.0.0-rc.12"
},
"devDependencies": {
"@babel/preset-env": "^7.21.5",
"babel-jest": "^27.1.1",
"@babel/preset-env": "^7.25.4",
"babel-jest": "^29.7.0",
"chokidar-cli": "^3.0.0",
"jest": "^27.1.1"
"jest": "^29.7.0"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit b52bdf6

Please sign in to comment.