From ec75522f427b86892f0842c7d953f48bf0b26cdb Mon Sep 17 00:00:00 2001 From: Sachin Raja Date: Tue, 23 Nov 2021 12:33:37 -0800 Subject: [PATCH] add deprecation warnings for icons/* imports (#6900) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add deprecation warnings for icons/* imports * do not log warnings during tests * update message Co-authored-by: Álvaro Mondéjar * remove message formatting * add jsdoc deprecation tags * Update scripts/build/package.js Co-authored-by: Álvaro Mondéjar * Update scripts/build/package.js Co-authored-by: Álvaro Mondéjar * Update scripts/build/package.js Co-authored-by: Álvaro Mondéjar * Update scripts/build/package.js Co-authored-by: Álvaro Mondéjar * fix "use" for jsdoc Co-authored-by: Álvaro Mondéjar --- scripts/build/package.js | 13 ++++++++++--- tests/icons.test.js | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/build/package.js b/scripts/build/package.js index 5ba2e7342..e1061808f 100644 --- a/scripts/build/package.js +++ b/scripts/build/package.js @@ -94,19 +94,26 @@ data.icons.forEach((icon) => { icons.push(icon); const iconObject = iconToObject(icon); + const iconExportName = slugToVariableName(icon.slug); // write the static .js file for the icon const jsFilepath = path.resolve(iconsDir, `${filename}.js`); - writeJs(jsFilepath, `module.exports=${iconObject};`); + const newImportMessage = `use "const { ${iconExportName} } = require('simple-icons/icons');" instead`; + const message = JSON.stringify( + `Imports like "const ${icon.slug} = require('simple-icons/icons/${icon.slug}');" have been deprecated in v6.0.0 and will no longer work from v7.0.0, ${newImportMessage}`, + ); + writeJs( + jsFilepath, + `console.warn("warn -", ${message});module.exports=${iconObject};`, + ); const dtsFilepath = path.resolve(iconsDir, `${filename}.d.ts`); writeTs( dtsFilepath, - 'declare const i:import("../alias").I;export default i;', + `/**@deprecated ${newImportMessage}*/declare const i:import("../alias").I;export default i;`, ); // add object to the barrel file - const iconExportName = slugToVariableName(icon.slug); iconsBarrelJs.push(`${iconExportName}:${iconObject},`); iconsBarrelMjs.push(`export const ${iconExportName}=${iconObject}`); iconsBarrelDts.push(`export const ${iconExportName}:I;`); diff --git a/tests/icons.test.js b/tests/icons.test.js index 8f28a16e1..6db0b467e 100644 --- a/tests/icons.test.js +++ b/tests/icons.test.js @@ -2,6 +2,8 @@ const { icons } = require('../_data/simple-icons.json'); const { getIconSlug } = require('../scripts/utils.js'); const testIcon = require('./test-icon.js'); +console.warn = () => {}; + icons.forEach((icon) => { const slug = getIconSlug(icon); const subject = require(`../icons/${slug}.js`);