From 44082ede880076d23aa5ae7e07269e296bfe6c03 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Sat, 20 Nov 2021 03:26:10 +0530 Subject: [PATCH] [v1.0.0-rc] Remove deprecated features (#2896) * Remove schemaDirectives from makeMergedSchema * Remove deprecated api-server command * Remove deprecated getConfig * Remove deprecated prop dataType from form * Remove deprecated data field in supabase client * Use transformValue instead of dataType in scaffold form * Revert "Remove deprecated api-server command" This reverts commit 15fdd40b877fb4510c5ef083f667018f3843be37. * Revert "Remove deprecated prop dataType from form" This reverts commit 8c8f64098a4541e14270b9f977ca319666b60302. * Revert "Use transformValue instead of dataType in scaffold form" This reverts commit 9e2c4ea4a0900eb9d81162dd5aa025d413d72c2e. * Remove deprecated api-server command * Remove deprecated global/ambient types * Revert "Remove deprecated data field in supabase client" This reverts commit 406e39db60415ffac09641cdf6ecafa4e9becda6. * Update yarn.lock * Remove deprecation warning for dbAuth scaffold * rm redwood tools * style: add back comment Co-authored-by: Daniel Choudhury Co-authored-by: Dominic Saadi Co-authored-by: Dominic Saadi <32992335+jtoar@users.noreply.github.com> Co-authored-by: David Price --- packages/cli/README.md | 31 +- packages/cli/package.json | 6 +- .../commands/generate/scaffold/scaffold.js | 7 - packages/cli/src/redwood-tools.js | 432 ------------------ packages/router/ambient.d.ts | 5 - packages/web/src/global.web-auto-imports.ts | 5 - yarn.lock | 2 - 7 files changed, 3 insertions(+), 485 deletions(-) delete mode 100644 packages/cli/src/redwood-tools.js diff --git a/packages/cli/README.md b/packages/cli/README.md index 9bd0fc89edc3..a384fbfe2fff 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -22,7 +22,6 @@ - [Adding a Destroyer](#adding-a-destroyer) - [Adding a Provider to the Auth Generator](#adding-a-provider-to-the-auth-generator) - [dbCommands](#dbcommands) - - [redwood-tools](#redwood-tools) - [Converting to TypeScript](#converting-to-typescript) - [Generators](#generators) - [What about...](#what-about) @@ -97,8 +96,6 @@ export const handler = (argv) => { } ``` -To get a good sense of the difference, compare [redwood-tools.js](https://github.com/redwoodjs/redwood/blob/d51ade08118c17459cebcdb496197ea52485364a/packages/cli/src/redwood-tools.js#L79-L167) to [dev.js](https://github.com/redwoodjs/redwood/blob/d51ade08118c17459cebcdb496197ea52485364a/packages/cli/src/commands/dev.js#L10-L77), or any other command. - ### Overview Contributing to `@redwoodjs/cli` usually means adding a command or modifying an existing one. We've organized this doc around adding a command since if you know how to do this you'll know how to modify one too. @@ -600,31 +597,6 @@ Adding or modifying a command here's no different—there's still a `command This is because most `dbCommands` are really just running prisma commands, so they really just have to output something like `yarn prisma ...`. -### redwood-tools - -[redwood-tools](https://github.com/redwoodjs/redwood/blob/main/packages/cli/src/redwood-tools.js) is Redwood's companion CLI development tool. -You can find a list of its commands in the top-level [contributing](https://github.com/redwoodjs/redwood/blob/main/CONTRIBUTING.md) guide. If you're contributing to `redwood-tools`, you're contributing in a way that helps people contribute, which is pretty meta. - -As mentioned, redwood-tools uses the "regular" yargs api, which is defined by method-chaining. -Adding a command here just entails adding another `command` method before the calls to `demandCommand` and `strict` at the end: - -```javascript -// ./src/commands/redwood-tools.js - -... - -.command( - ['hello', 'h'], - 'Say hi', - {}, - () => console.log('hi!') -) -.demandCommand() -.strict().argv -``` - -Contrived example aside, any command you add here should help people contribute to Redwood. - #### Generators If you're converting a generator, read the _Goals_ section of tracking issue [#523](https://github.com/redwoodjs/redwood/issues/523); it details some specs you should comply with. @@ -651,8 +623,7 @@ redwood/packages/cli ├── commands ├── index.d.ts ├── index.js - ├── lib - └── redwood-tools.js + └── lib ``` #### index.js diff --git a/packages/cli/package.json b/packages/cli/package.json index 01fb84184fae..1c89d9876c03 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -5,10 +5,8 @@ "license": "MIT", "bin": { "redwood": "./dist/index.js", - "redwood-tools": "./dist/redwood-tools.js", "rw": "./dist/index.js", - "rwfw": "./dist/rwfw.js", - "rwt": "./dist/redwood-tools.js" + "rwfw": "./dist/rwfw.js" }, "repository": { "type": "git", @@ -66,7 +64,7 @@ "prepublishOnly": "yarn build", "build:clean-dist": "rimraf 'dist/**/*/__tests__'", "build:js": "babel src -d dist --extensions \".js,.ts,.tsx\" --copy-files --no-copy-ignored && yarn build:clean-dist", - "fix:permissions": "chmod +x dist/index.js dist/redwood-tools.js dist/rwfw.js", + "fix:permissions": "chmod +x dist/index.js dist/rwfw.js", "build:watch": "nodemon --watch src --ext \"js,ts,tsx,template\" --ignore dist --exec \"yarn build && yarn fix:permissions\"", "test": "jest src", "test:watch": "yarn test --watch" diff --git a/packages/cli/src/commands/generate/scaffold/scaffold.js b/packages/cli/src/commands/generate/scaffold/scaffold.js index b0d35b4c3b52..f7a0f3ca476c 100644 --- a/packages/cli/src/commands/generate/scaffold/scaffold.js +++ b/packages/cli/src/commands/generate/scaffold/scaffold.js @@ -689,13 +689,6 @@ export const handler = async ({ typescript, tailwind, }) => { - /** @deprecated Used to be able to create dbAuth pages with `yarn rw g scaffold dbAuth` */ - if (modelArg.toLowerCase() === 'dbauth') { - console.info(c.green('\nGenerate dbAuth pages with:\n')) - console.info(' yarn rw generate dbAuth\n') - process.exit(0) - } - if (tests === undefined) { tests = getConfig().generate.tests } diff --git a/packages/cli/src/redwood-tools.js b/packages/cli/src/redwood-tools.js deleted file mode 100644 index f318b7a8464b..000000000000 --- a/packages/cli/src/redwood-tools.js +++ /dev/null @@ -1,432 +0,0 @@ -#!/usr/bin/env node -import fs from 'fs' -import path from 'path' - -import boxen from 'boxen' -import chokidar from 'chokidar' -import execa from 'execa' -import _, { omit } from 'lodash' -import prettier from 'prettier' -import rimraf from 'rimraf' -import yargs from 'yargs' - -import { ensurePosixPath, getPaths } from '@redwoodjs/internal' - -import c from './lib/colors' - -const RW_BINS = { - redwood: 'cli/dist/index.js', - rw: 'cli/dist/index.js', - 'redwood-tools': 'cli/dist/redwood-tools.js', - rwt: 'cli/dist/redwood-tools.js', - 'api-server': 'api-server/dist/index.js', - 'rw-api-server': 'api-server/dist/index.js', - 'rw-api-build': 'core/esbuild/index.js', - 'rw-gen': 'internal/dist/generate/generate.js', - 'rw-gen-watch': 'internal/dist/generate/watch.js', -} - -export const resolveFrameworkPath = (RW_PATH) => { - if (!fs.existsSync(RW_PATH)) { - console.error(`Error: '${RW_PATH}' does not exist`) - process.exit(1) - } - return path.resolve(process.cwd(), RW_PATH) -} - -export const fixBinaryPermissions = (PROJECT_PATH) => { - Object.keys(RW_BINS) - .map((name) => { - return path.join(PROJECT_PATH, 'node_modules/.bin/', name) - }) - .forEach((binFile) => { - try { - fs.chmodSync(binFile, '755') - } catch (e) { - console.warn(`Warning: Could not chmod ${binFile}`) - console.log(e) - } - }) -} - -export const fixProjectBinaries = (PROJECT_PATH) => { - Object.keys(RW_BINS) - .map((name) => { - const from = path.join(PROJECT_PATH, 'node_modules/.bin/', name) - const to = path.join( - PROJECT_PATH, - 'node_modules/@redwoodjs', - RW_BINS[name] - ) - console.log(`symlink '${from}' -> '${to}'`) - return [from, to] - }) - .forEach(([from, to]) => { - try { - fs.unlinkSync(from) - } catch (e) { - console.warn(`Warning: Could not unlink ${from}`) - } - try { - fs.symlinkSync(to, from) - } catch (e) { - console.warn(`Warning: Could not symlink ${from} -> ${to}`) - console.log(e) - } - try { - fs.chmodSync(from, '755') - } catch (e) { - console.warn(`Warning: Could not chmod ${from}`) - console.log(e) - } - }) -} - -export const copyFiles = async (src, dest) => { - // TODO: Figure out if we need to only run based on certain events. - - src = ensurePosixPath(src) - dest = ensurePosixPath(dest) - - await execa( - 'rsync', - [ - `-rtvu --delete --exclude "create-redwood-app/template"`, - `'${src}'`, - `'${dest}'`, - ], - { - shell: true, - stdio: 'inherit', - cleanup: true, - } - ) - // when rsync is run modify the permission to make binaries executable. - fixProjectBinaries(getPaths().base) -} - -const rwtCopy = ({ RW_PATH = process.env.RW_PATH }) => { - RW_PATH = resolveFrameworkPath(RW_PATH) - - console.log(`Redwood Framework Path: ${c.info(RW_PATH)}`) - - const src = `${RW_PATH}/packages/` - const dest = `${getPaths().base}/node_modules/@redwoodjs/` // eslint-disable-line - - copyFiles(src, dest) -} - -const rwtCopyWatch = ({ RW_PATH = process.env.RW_PATH }) => { - RW_PATH = resolveFrameworkPath(RW_PATH) - - console.log(`Redwood Framework Path: ${c.info(RW_PATH)}`) - - const src = `${RW_PATH}/packages/` - const dest = `${getPaths().base}/node_modules/@redwoodjs/` - - chokidar - .watch(src, { - persistent: true, - recursive: true, - ignored: [path.join(src, 'packages/create-redwood-app/template')], - }) - .on( - 'all', - _.debounce((event) => { - // TODO: Figure out if we need to only run based on certain events. - console.log('Trigger event: ', event) - copyFiles(src, dest) - }, 500) - ) -} - -const rwtLink = async (yargs) => { - const RW_PATH = yargs.RW_PATH || process.env.RW_PATH - const { clean, watch, only } = yargs - - if (!RW_PATH) { - console.error(c.error('You must specify a path to your local redwood repo')) - console.error(c.error("Or set RW_PATH in your shell's environment")) - process.exit(1) - return - } - - const frameworkPath = resolveFrameworkPath(RW_PATH) - - console.log(`\n Redwood Framework Path: ${c.info(frameworkPath)}`) - - const frameworkPackagesPath = path.join(frameworkPath, 'packages/') - const projectPackagesPath = path.join( - getPaths().base, - 'node_modules/_redwood-linked-packages' - ) - - console.log( - `Copying your local Redwood build from ${c.info(frameworkPackagesPath)} \n` - ) - - if (!fs.existsSync(projectPackagesPath)) { - fs.mkdirSync(projectPackagesPath) - } - - updateProjectWithResolutions(frameworkPackagesPath) - - if (clean) { - await execa('yarn build:clean', { - shell: true, - stdio: 'inherit', - cleanup: true, - cwd: frameworkPath, - }) - } - - // Inform user to unlink framework repo, when process cancelled - process.on('SIGINT', () => { - const message = ` - 🙏 Thanks for contributing..\n - Please run ${c.green('yarn rwt unlink')} to restore your project - ` - console.log( - boxen(message, { - padding: { top: 0, bottom: 0, right: 1, left: 1 }, - margin: 1, - borderColour: 'gray', - }) - ) - }) - - const onlyParams = only ? ['--only', only] : [] - - await execa( - 'node ./tasks/build-and-copy', - ['--dest', `"${projectPackagesPath}"`, ...onlyParams], - { - shell: true, - stdio: 'inherit', - cleanup: true, - cwd: frameworkPath, - } - ) - - // Delete existing redwood folders in node_modules - // Do this right before install, incase build:link fails - rimraf.sync(path.join(getPaths().base, 'node_modules/@redwoodjs/')) - - // Let workspaces do the link - await execa('yarn install', ['--pure-lockfile', '--check-files'], { - shell: true, - stdio: 'inherit', - cleanup: true, - cwd: getPaths().base, - }) - - fixBinaryPermissions(getPaths().base) - - const message = ` - ${c.bold('🚀 Go Forth and Contribute!')}\n - 🔗 Your project is linked!\n - Contributing doc: ${c.underline('https://redwoodjs.com/docs/contributing')} - ` - console.log( - boxen(message, { - padding: { top: 0, bottom: 0, right: 1, left: 1 }, - margin: 1, - borderColour: 'gray', - }) - ) - - if (watch) { - // Restart build:link scripts in watchmode - execa( - 'yarn build:link', - ['--dest', `"${projectPackagesPath}"`, '--watch', ...onlyParams], - { - shell: true, - stdio: 'inherit', - cleanup: true, - cwd: frameworkPath, - } - ) - } -} - -// This should be synchronous -const rwtUnlink = () => { - const linkedPackagesPath = path.join( - getPaths().base, - 'node_modules/_redwood-linked-packages' - ) - if (fs.existsSync(linkedPackagesPath)) { - // remove resolutions we added in link - updateProjectWithResolutions(linkedPackagesPath, true) - - rimraf.sync(path.join(getPaths().base, 'node_modules/@redwoodjs')) - - rimraf.sync(linkedPackagesPath) - } - - execa.sync('yarn install', ['--check-files'], { - shell: true, - stdio: 'inherit', - cleanup: true, - cwd: getPaths().base, - }) - - return process.exit(0) -} - -const rwtInstall = ({ packageName }) => { - // This command upgrades a Redwood package from the local NPM registry. You - // run the local registry from `./tasks/run-local-npm`. - // See `CONTRIBUTING.md` for more information. - const pkgPath = path.join(getPaths().base, 'node_modules', packageName) - console.log(`Deleting ${pkgPath}`) - try { - fs.rmdirSync(pkgPath, { recursive: true }) - } catch (e) { - console.error(`Error: Could not delete ${pkgPath}`) - process.exit(1) - } - - execa( - 'yarn', - [ - 'upgrade', - `${packageName}@dev`, - '--no-lockfile', - '--registry http://localhost:4873/', - '--check-files', - ], - { - shell: true, - cwd: getPaths().base, - stdio: 'inherit', - extendEnv: true, - cleanup: true, - } - ) -} - -const getRwPackagesToLink = (packagesPath) => { - const packageFolders = fs.readdirSync(packagesPath) - - return packageFolders - .filter((folderName) => folderName !== 'create-redwood-app') - .filter((item) => !/(^|\/)\.[^\/\.]/g.test(item)) // filter hidden files - .map((packageFolder) => { - return `@redwoodjs/${packageFolder}` - }) -} - -const updateProjectWithResolutions = (redwoodPackagesPath, remove) => { - const pkgJSONPath = path.join(getPaths().base, 'package.json') - const packageJSON = require(pkgJSONPath) - - const frameworkVersion = require(path.join( - redwoodPackagesPath, - 'cli/package.json' - )).version - - const frameworkRepoResolutions = getRwPackagesToLink( - redwoodPackagesPath - ).reduce((resolutions, packageName) => { - resolutions[packageName] = frameworkVersion - return resolutions - }, {}) - - let resolutions = packageJSON.resolutions - let packages = packageJSON.workspaces.packages - - if (remove) { - resolutions = omit(resolutions, Object.keys(frameworkRepoResolutions)) - packages = packages.filter( - (workspaceFolder) => - workspaceFolder !== 'node_modules/_redwood-linked-packages/*' - ) - } else { - resolutions = { - ...resolutions, - ...frameworkRepoResolutions, - } - if (!packages.includes('node_modules/_redwood-linked-packages/*')) { - packages.push('node_modules/_redwood-linked-packages/*') - } - } - - const updatedPackageJSON = { - ...packageJSON, - workspaces: { - packages, - }, - resolutions, - } - - fs.writeFileSync( - pkgJSONPath, - prettier.format(JSON.stringify(updatedPackageJSON), { - parser: 'json-stringify', - }) - ) -} - -// eslint-disable-next-line no-unused-expressions -yargs - .command( - ['copy [RW_PATH]', 'cp'], - 'Copy the Redwood Framework path to this project', - {}, - rwtCopy - ) - .command( - ['copy:watch [RW_PATH]', 'cpw'], - 'Watch the Redwood Framework path for changes and copy them over to this project', - {}, - rwtCopyWatch - ) - .command({ - command: 'link [RW_PATH]', - aliases: ['l'], - builder: (yargs) => { - return yargs - .option('clean', { - alias: 'c', - type: 'boolean', - description: 'Clean the redwood dist folders first.', - default: true, - }) - .option('watch', { - alias: 'w', - type: 'boolean', - description: 'Build and watch the supplied redwood repo', - default: true, - }) - .option('only', { - alias: 'only', - type: 'string', - description: 'Specify folder to link from RW_PATH/packages', - }) - }, - desc: 'Run your local version of redwood in this project', - handler: rwtLink, - }) - .command({ - command: 'unlink', - desc: 'Unlink your local version of redwood, and use the one specified in package.json', - handler: rwtUnlink, - }) - .command( - ['install [packageName]', 'i'], - 'Install a package from your local NPM registry', - () => {}, - rwtInstall - ) - .command( - ['fix-bins', 'fix'], - 'Fix Redwood symlinks and permissions', - {}, - () => { - fixProjectBinaries(getPaths().base) - } - ) - .demandCommand() - .strict().argv diff --git a/packages/router/ambient.d.ts b/packages/router/ambient.d.ts index ad491cd07176..59d6fb505603 100644 --- a/packages/router/ambient.d.ts +++ b/packages/router/ambient.d.ts @@ -19,11 +19,6 @@ declare global { **/ var RWJS_API_URL: string - /** @deprecated Please use `RWJS_API_GRAPHQL_URL` or `RWJS_API_DBAUTH_URL` */ - var __REDWOOD__API_URL: string - /** @deprecated Please use `RWJS_API_GRAPHQL_URL` or `RWJS_API_DBAUTH_URL` */ - var __REDWOOD__API_GRAPHQL_SERVER_PATH: string - namespace NodeJS { interface Global { /** diff --git a/packages/web/src/global.web-auto-imports.ts b/packages/web/src/global.web-auto-imports.ts index 6aa6a0840eb7..6c8a756e5514 100644 --- a/packages/web/src/global.web-auto-imports.ts +++ b/packages/web/src/global.web-auto-imports.ts @@ -12,11 +12,6 @@ declare global { const gql: typeof _gql interface Window { - /** - * @deprecated Please use RWJS_API_GRAPHQL_URL or RWJS_API_DBAUTH_URL - */ - __REDWOOD__API_PROXY_PATH: never - /** URL or absolute path to the DbAuth serverless function */ RWJS_API_DBAUTH_URL: string /** URL or absolute path to the GraphQL serverless function */ diff --git a/yarn.lock b/yarn.lock index 78f9e2301c33..f4f18068df64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4152,10 +4152,8 @@ __metadata: yargs: 16.2.0 bin: redwood: ./dist/index.js - redwood-tools: ./dist/redwood-tools.js rw: ./dist/index.js rwfw: ./dist/rwfw.js - rwt: ./dist/redwood-tools.js languageName: unknown linkType: soft