From 48e78bbd7c6830bc73aa1916970f3d656ccb54f8 Mon Sep 17 00:00:00 2001 From: Matyas Szabo Date: Fri, 13 Sep 2024 17:14:58 +0200 Subject: [PATCH] fix(console): remove __PURE__ annotation from console to fix warnings in Vite/Rollup It was in the wrong place and 2 times. The whole macro was used just to add these buggy annotations --- package-lock.json | 17 +----- packages/console/package.json | 8 +-- packages/console/src/index.ts | 25 +++----- packages/console/src/macro.js | 83 --------------------------- packages/ui-babel-preset/lib/index.js | 2 +- 5 files changed, 11 insertions(+), 124 deletions(-) delete mode 100644 packages/console/src/macro.js diff --git a/package-lock.json b/package-lock.json index e9842e96f9..790cba7627 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10290,15 +10290,6 @@ "@babel/types": "^7.20.7" } }, - "node_modules/@types/babel-plugin-macros": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@types/babel-plugin-macros/-/babel-plugin-macros-3.1.3.tgz", - "integrity": "sha512-JU+MgpsHK3taY18mBETy5XlwY6LVngte7QXYzUuXEaaX0CN8dBqbjXtADe+gJmkSQE1FJHufzPj++OWZlhRmGw==", - "dev": true, - "dependencies": { - "@types/babel__core": "*" - } - }, "node_modules/@types/body-parser": { "version": "1.19.2", "license": "MIT", @@ -40252,14 +40243,8 @@ "name": "@instructure/console", "version": "10.2.2", "license": "MIT", - "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-module-imports": "^7.24.3", - "babel-plugin-macros": "^3.1.0" - }, "devDependencies": { - "@instructure/ui-babel-preset": "10.2.2", - "@types/babel-plugin-macros": "^3.1.3" + "@instructure/ui-babel-preset": "10.2.2" }, "peerDependencies": { "react": ">=16.8 <=18" diff --git a/packages/console/package.json b/packages/console/package.json index 1b13ed8fea..04d34340ff 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -23,13 +23,7 @@ }, "license": "MIT", "devDependencies": { - "@instructure/ui-babel-preset": "10.2.2", - "@types/babel-plugin-macros": "^3.1.3" - }, - "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-module-imports": "^7.24.3", - "babel-plugin-macros": "^3.1.0" + "@instructure/ui-babel-preset": "10.2.2" }, "peerDependencies": { "react": ">=16.8 <=18" diff --git a/packages/console/src/index.ts b/packages/console/src/index.ts index 968548953f..2d739fa64c 100644 --- a/packages/console/src/index.ts +++ b/packages/console/src/index.ts @@ -31,16 +31,6 @@ import { debug } from './console' -import { - error as logError, - warn as logWarn, - warnDeprecated as logWarnDeprecated, - info as logInfo, - assert as logAssert, - debug as logDebug, - log as consoleLog -} from './macro' - export { error, warn, @@ -49,11 +39,12 @@ export { info, assert, debug, - logError, - logWarn, - logWarnDeprecated, - logInfo, - logDebug, - logAssert, - consoleLog + // kept for backwards compatibility, will be removed later + error as logError, + warn as logWarn, + warnDeprecated as logWarnDeprecated, + info as logInfo, + debug as logDebug, + assert as logAssert, + log as consoleLog } diff --git a/packages/console/src/macro.js b/packages/console/src/macro.js deleted file mode 100644 index 3a4fe69c43..0000000000 --- a/packages/console/src/macro.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 - present Instructure, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -const { createMacro } = require('babel-plugin-macros') -const annotateAsPure = require('@babel/helper-annotate-as-pure').default -const { addNamed } = require('@babel/helper-module-imports') - -function macro({ babel, references, state }) { - Object.keys(references).forEach((referenceKey) => { - const runtimeNode = addNamed( - state.file.path, - referenceKey, - '@instructure/console' - ) - const t = babel.types - - references[referenceKey].reverse().forEach((reference) => { - const path = reference.parentPath - - reference.replaceWith(t.cloneDeep(runtimeNode)) - - // add pure function annotation - // so that consumers can remove console statements from prod bundles - if (process.env.NODE_ENV === 'production') { - path.traverse({ - Function: annotateAsPure - }) - annotateAsPure(reference) - annotateAsPure(path) - } - }) - }) -} - -module.exports = createMacro(macro) - -/** - * @callback LogFunc - * @param {boolean} isSuppressed Must be false to log anything. - * @param {string} message The message to log. - * @param {...*} [restParam] anything else to log. - * @returns void - */ - -/** - * Logs a message to the console if its not a production build. - * @type LogFunc - */ -exports.error = exports.warn = createMacro(macro) - -/** - * Logs a deprecation message to the console if its not a production build and - * the `OMIT_INSTUI_DEPRECATION_WARNINGS` env var is not set or is set to `false` - * @type LogFunc - */ -exports.warnDeprecated = createMacro(macro) - -/** - * Logs a message to the console. - * @type {function(...*): void} - */ -exports.info = exports.assert = exports.debug = exports.log = createMacro(macro) diff --git a/packages/ui-babel-preset/lib/index.js b/packages/ui-babel-preset/lib/index.js index 83b872eaa4..484004eac8 100644 --- a/packages/ui-babel-preset/lib/index.js +++ b/packages/ui-babel-preset/lib/index.js @@ -174,7 +174,7 @@ function getWebEnvConfig(opts) { }, useBuiltIns: 'entry', // this version has to match the version in package.json - corejs: '3.26.1', + corejs: '3.37.1', modules: opts.esModules ? false : 'commonjs', // debug: true, // un-comment if you want to see what browsers are being targeted and what plugins that means it will activate exclude: ['transform-typeof-symbol'],