From e6a5373416e3b9800e86e4288bab1d8ebd690ada Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Nov 2022 12:36:07 -0500 Subject: [PATCH 1/6] 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({ From 8ae916609a756e7820d5f60389e78427aed964bd Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Nov 2022 12:36:29 -0500 Subject: [PATCH 2/6] Single deprecation warning per remix index file --- packages/remix-dev/cli/setup.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/remix-dev/cli/setup.ts b/packages/remix-dev/cli/setup.ts index 7d6f3303be5..a63bebdb065 100644 --- a/packages/remix-dev/cli/setup.ts +++ b/packages/remix-dev/cli/setup.ts @@ -94,7 +94,16 @@ async function combineFilesInDirs( dirs: string[], ext: string ): Promise { - let combined = ""; + let logDeprecationWarning = + `console.warn("WARNING: All \`remix\` exports are considered deprecated as of v1.3.3. ` + + `All imports should come from their respective packages (i.e., ` + + `\`@remix-run/server-runtime\`, \`@remix-run/react\`, etc.). ` + + `Run \`npx @remix-run/dev@latest codemod replace-remix-magic-imports\` to ` + + `automatically migrate your code.");\n\n`; + + // Don't include the warning in type declarations + let combined = ext === ".d.ts" ? "" : logDeprecationWarning; + for (let dir of dirs) { let files = await fse.readdir(dir); for (let file of files) { From 12ae44f31f71ce99bfc463cc8c28d524e32350c4 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Nov 2022 14:42:30 -0500 Subject: [PATCH 3/6] Revert "Single deprecation warning per remix index file" This reverts commit 77744927d997a44ba196d61c64c423b061171321. --- packages/remix-dev/cli/setup.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/remix-dev/cli/setup.ts b/packages/remix-dev/cli/setup.ts index a63bebdb065..7d6f3303be5 100644 --- a/packages/remix-dev/cli/setup.ts +++ b/packages/remix-dev/cli/setup.ts @@ -94,16 +94,7 @@ async function combineFilesInDirs( dirs: string[], ext: string ): Promise { - let logDeprecationWarning = - `console.warn("WARNING: All \`remix\` exports are considered deprecated as of v1.3.3. ` + - `All imports should come from their respective packages (i.e., ` + - `\`@remix-run/server-runtime\`, \`@remix-run/react\`, etc.). ` + - `Run \`npx @remix-run/dev@latest codemod replace-remix-magic-imports\` to ` + - `automatically migrate your code.");\n\n`; - - // Don't include the warning in type declarations - let combined = ext === ".d.ts" ? "" : logDeprecationWarning; - + let combined = ""; for (let dir of dirs) { let files = await fse.readdir(dir); for (let file of files) { From 5083780b58e6a9b54faa7971da54d508cb887df9 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Nov 2022 14:45:47 -0500 Subject: [PATCH 4/6] Add back in TS deprecation typings --- rollup.utils.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/rollup.utils.js b/rollup.utils.js index 183b13b1447..2aff5301173 100644 --- a/rollup.utils.js +++ b/rollup.utils.js @@ -1,5 +1,5 @@ const babel = require("@rollup/plugin-babel").default; -const { camelCase } = require("lodash"); +const { camelCase, upperFirst } = require("lodash"); const copy = require("rollup-plugin-copy"); const fs = require("fs"); const fse = require("fs-extra"); @@ -184,6 +184,7 @@ 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 = @@ -195,7 +196,15 @@ function magicExportsPlugin({ packageName, version }) { if (magicExports.values) { 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"); let cjsModule = camelCase(packageName.slice("@remix-run/".length)); cjsContents += `var ${cjsModule} = require('${packageName}');\n`; @@ -209,8 +218,16 @@ function magicExportsPlugin({ packageName, version }) { } if (magicExports.types) { - let exportList = magicExports.types.join(", "); - tsContents += `export type { ${exportList} } from '${packageName}';\n`; + 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"); } this.emitFile({ From 229503e63a091b703ae2918a7db2ffcd08092a5f Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Nov 2022 14:55:06 -0500 Subject: [PATCH 5/6] Warn on deprecated remix imports via esbuild plugin --- packages/remix-dev/compiler/compileBrowser.ts | 2 ++ packages/remix-dev/compiler/compilerServer.ts | 2 ++ .../plugins/deprecatedRemixPackagePlugin.ts | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 packages/remix-dev/compiler/plugins/deprecatedRemixPackagePlugin.ts diff --git a/packages/remix-dev/compiler/compileBrowser.ts b/packages/remix-dev/compiler/compileBrowser.ts index b279ea05a9b..93bf3decb42 100644 --- a/packages/remix-dev/compiler/compileBrowser.ts +++ b/packages/remix-dev/compiler/compileBrowser.ts @@ -11,6 +11,7 @@ import { loaders } from "./loaders"; import { type CompileOptions } from "./options"; import { browserRouteModulesPlugin } from "./plugins/browserRouteModulesPlugin"; import { cssFilePlugin } from "./plugins/cssFilePlugin"; +import { deprecatedRemixPackagePlugin } from "./plugins/deprecatedRemixPackagePlugin"; import { emptyModulesPlugin } from "./plugins/emptyModulesPlugin"; import { mdxPlugin } from "./plugins/mdx"; import { urlImportsPlugin } from "./plugins/urlImportsPlugin"; @@ -70,6 +71,7 @@ const createEsbuildConfig = ( } let plugins = [ + deprecatedRemixPackagePlugin(options.onWarning), cssFilePlugin(options), urlImportsPlugin(), mdxPlugin(config), diff --git a/packages/remix-dev/compiler/compilerServer.ts b/packages/remix-dev/compiler/compilerServer.ts index 6ad1c12710c..b0daa4b6a2a 100644 --- a/packages/remix-dev/compiler/compilerServer.ts +++ b/packages/remix-dev/compiler/compilerServer.ts @@ -9,6 +9,7 @@ import { type AssetsManifest } from "./assets"; import { loaders } from "./loaders"; import { type CompileOptions } from "./options"; import { cssFilePlugin } from "./plugins/cssFilePlugin"; +import { deprecatedRemixPackagePlugin } from "./plugins/deprecatedRemixPackagePlugin"; import { emptyModulesPlugin } from "./plugins/emptyModulesPlugin"; import { mdxPlugin } from "./plugins/mdx"; import { serverAssetsManifestPlugin } from "./plugins/serverAssetsManifestPlugin"; @@ -47,6 +48,7 @@ const createEsbuildConfig = ( let isDenoRuntime = config.serverBuildTarget === "deno"; let plugins: esbuild.Plugin[] = [ + deprecatedRemixPackagePlugin(options.onWarning), cssFilePlugin(options), urlImportsPlugin(), mdxPlugin(config), diff --git a/packages/remix-dev/compiler/plugins/deprecatedRemixPackagePlugin.ts b/packages/remix-dev/compiler/plugins/deprecatedRemixPackagePlugin.ts new file mode 100644 index 00000000000..80de228c150 --- /dev/null +++ b/packages/remix-dev/compiler/plugins/deprecatedRemixPackagePlugin.ts @@ -0,0 +1,29 @@ +import path from "path"; +import type { Plugin } from "esbuild"; + +/** + * A plugin to warn users when importing from the deprecated `remix` package + */ +export function deprecatedRemixPackagePlugin( + onWarning?: (warning: string, key: string) => void +): Plugin { + return { + name: "deprecated-remix-package", + setup(build) { + build.onResolve({ filter: /.*/ }, ({ importer, path: filePath }) => { + // Warn on deprecated imports from the remix package + if (filePath === "remix") { + let relativePath = path.relative(process.cwd(), importer); + let warningMessage = + `WARNING: All \`remix\` exports are considered deprecated as of v1.3.3. ` + + `Please change your import in "${relativePath}" to come from the respective ` + + `underlying \`@remix-run/*\` package. ` + + `Run \`npx @remix-run/dev@latest codemod replace-remix-magic-imports\` ` + + `to automatically migrate your code.`; + onWarning?.(warningMessage, importer); + } + return undefined; + }); + }, + }; +} From 72a22c9438267f42138efa11f4512bbfef3a0c89 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 21 Nov 2022 15:05:04 -0500 Subject: [PATCH 6/6] add chgangeset --- .changeset/sharp-ears-begin.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/sharp-ears-begin.md diff --git a/.changeset/sharp-ears-begin.md b/.changeset/sharp-ears-begin.md new file mode 100644 index 00000000000..7a7edf0ea24 --- /dev/null +++ b/.changeset/sharp-ears-begin.md @@ -0,0 +1,6 @@ +--- +"remix": patch +"@remix-run/dev": patch +--- + +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.