From e6a5373416e3b9800e86e4288bab1d8ebd690ada Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Nov 2022 12:36:07 -0500 Subject: [PATCH] Revert "Deprecate all functions & types exported from `magicExports` (#3284)" This reverts commit 848d8b04d409942a5444988feb5ae13a47f52455. --- .changeset/khaki-meals-prove.md | 12 ------ rollup.utils.js | 76 +++++++++------------------------ 2 files changed, 20 insertions(+), 68 deletions(-) delete mode 100644 .changeset/khaki-meals-prove.md diff --git a/.changeset/khaki-meals-prove.md b/.changeset/khaki-meals-prove.md deleted file mode 100644 index 2fa711c0efd..00000000000 --- a/.changeset/khaki-meals-prove.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -"@remix-run/architect": minor -"@remix-run/cloudflare": minor -"@remix-run/node": minor -"@remix-run/react": minor -"@remix-run/server-runtime": minor ---- - -Importing functions and types from the `remix` package is deprecated, and all -exported modules will be removed in the next major release. For more details, -[see the release notes for 1.4.0](https://github.com/remix-run/remix/releases/tag/v1.4.0) -where these changes were first announced. diff --git a/rollup.utils.js b/rollup.utils.js index 6a0d4301b48..183b13b1447 100644 --- a/rollup.utils.js +++ b/rollup.utils.js @@ -1,10 +1,10 @@ -const fs = require("fs"); -const path = require("path"); const babel = require("@rollup/plugin-babel").default; -const nodeResolve = require("@rollup/plugin-node-resolve").default; -const fse = require("fs-extra"); -const { camelCase, upperFirst } = require("lodash"); +const { camelCase } = require("lodash"); const copy = require("rollup-plugin-copy"); +const fs = require("fs"); +const fse = require("fs-extra"); +const nodeResolve = require("@rollup/plugin-node-resolve").default; +const path = require("path"); const REPO_ROOT_DIR = __dirname; @@ -184,69 +184,33 @@ function magicExportsPlugin({ packageName, version }) { } let banner = createBanner(packageName, version); - let moduleName = camelCase(packageName.slice("@remix-run/".length)); let esmContents = banner + "\n"; let tsContents = banner + "\n"; let cjsContents = banner + "\n" + "'use strict';\n" + - "Object.defineProperty(exports, '__esModule', { value: true });\n\n"; + "Object.defineProperty(exports, '__esModule', { value: true });\n"; if (magicExports.values) { - let deprecationFunctions = - // eslint-disable-next-line no-template-curly-in-string - "const getDeprecatedMessage = (symbol, packageName) => `All \\`remix\\` exports are considered deprecated as of v1.3.3. Please import \\`${symbol}\\` from \\`${packageName}\\` instead. Run \\`npx @remix-run/dev@latest codemod replace-remix-magic-imports\\` to automatically migrate your code.`;\n" + - "const warn = (fn, message) => (...args) => {\n" + - " console.warn(message);\n" + - " return fn(...args);\n" + - "};\n\n"; - - esmContents += - `import * as ${moduleName} from '${packageName}';\n` + - deprecationFunctions; - esmContents += magicExports.values - .map( - (symbol) => - `/** @deprecated Import \`${symbol}\` from \`${packageName}\` instead. */\n` + - `const ${symbol} = warn(${moduleName}.${symbol}, getDeprecatedMessage('${symbol}', '${packageName}'));\n` - ) - .join("\n"); - esmContents += `\nexport { ${magicExports.values.join(", ")} };\n`; + let exportList = magicExports.values.join(", "); + esmContents += `export { ${exportList} } from '${packageName}';\n`; + tsContents += `export { ${exportList} } from '${packageName}';\n`; - tsContents += `import * as ${moduleName} from '${packageName}';\n\n`; - tsContents += magicExports.values - .map( - (symbol) => - `/** @deprecated Import \`${symbol}\` from \`${packageName}\` instead. */\n` + - `export declare const ${symbol}: typeof ${moduleName}.${symbol};\n` - ) - .join("\n"); - - cjsContents += - `var ${moduleName} = require('${packageName}');\n` + - deprecationFunctions; - cjsContents += magicExports.values - .map( - (symbol) => - `/** @deprecated Import \`${symbol}\` from \`${packageName}\` instead. */\n` + - `const ${symbol} = warn(${moduleName}.${symbol}, getDeprecatedMessage('${symbol}', '${packageName}'));\n` + - `exports.${symbol} = ${symbol};\n` - ) - .join("\n"); + let cjsModule = camelCase(packageName.slice("@remix-run/".length)); + cjsContents += `var ${cjsModule} = require('${packageName}');\n`; + for (let symbol of magicExports.values) { + cjsContents += + `Object.defineProperty(exports, '${symbol}', {\n` + + " enumerable: true,\n" + + ` get: function () { return ${cjsModule}.${symbol}; }\n` + + "});\n"; + } } if (magicExports.types) { - let typesModuleName = `${upperFirst(moduleName)}Types`; - - tsContents += `import * as ${typesModuleName} from '${packageName}';\n\n`; - tsContents += magicExports.types - .map( - (symbol) => - `/** @deprecated Import type \`${symbol}\` from \`${packageName}\` instead. */\n` + - `export declare type ${symbol} = ${typesModuleName}.${symbol};\n` - ) - .join("\n"); + let exportList = magicExports.types.join(", "); + tsContents += `export type { ${exportList} } from '${packageName}';\n`; } this.emitFile({