Coder Social home page Coder Social logo

hypermod-io / hypermod-community Goto Github PK

View Code? Open in Web Editor NEW
130.0 3.0 18.0 11.14 MB

Community-owned global registry and documentation hub for codemods. Write & run codemods, share them with your friends!

Home Page: http://www.codeshiftcommunity.com/

License: MIT License

JavaScript 5.85% TypeScript 75.27% CSS 0.56% MDX 18.32%
codemod codemods codeshift jscodeshift dependency upgrade cli

hypermod-community's People

Contributors

alexreardon avatar coderaiser avatar danieldelcore avatar danielo515 avatar github-actions[bot] avatar haroenv avatar kiprasmel avatar paul-vd avatar pawk3k avatar rajasegar avatar sawyerh avatar tomheller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hypermod-community's Issues

Support publishing codemods to npm from external repos

For users not publishing codemods to the community folder, we want to still provide a way for consumers to bundle + publish their codemods for use with our CLI.

Related thread: facebook/jscodeshift#126

This might look a little something like this:

@codeshift/cli publish path/to/transform

Dependency management might be an interesting challenge, but i think we can solve that by requiring transforms to also be accompanied by a codeshift.config.js file containing everything it needs.

Codemods should be able to be co-located with normal NPM packages

Codemods should be shareable via normal npm packages.

This would mean that a package like react could create a codeshift.config.js and link transforms.

Codeshift cli will then pull the package and attempt to locate a config file. If that file is not found, it will attempt to pull a codemod from the community folder.

CLI to support publish for external codemods

Allow for packages outside of the community repo to be published with the CLI to an npm namespace / registry of the user's choice.

It will need to:

  • Init ✅
  • Validate ✅
  • Build
  • Version ??? (maybe)
  • Publish

CLI to support "Upgrade" command

The upgrade command would work similarly to the github bot.

  • It will search your package.json for dependencies
  • If any of those dependencies have a codemod that can be run respective to the current version
  • Run the codemod and bump the package.json

`codeshift-cli` package doesn't exist on npm

hey, the stuff you added in #58 is very exciting!

i think only problem is that the codeshift-cli package is not available on npm yet?

i would actually consider naming it codemods-cli - since end consumers of the library don't necessarily know what "codeshift" is, but do know what a "codemod" is - i think it'd be better understandable.

Interactive CLI

We should add some interactive options in the case that information is missing on run.

IE if a transform isn't specified:

codeshift -p react

The cli should output an interactive list of codemods to run.

- v10.0.0
- v18.0.0
- ...

This could also be applied to other flags and sub commands like list

NPX download time

npx @codeshift/cli --packages @atlaskit/[email protected] .temp/src/Avatar.tsx

Running codeshift/cli via npx takes FAR too long to be worthwhile..

We need to investigate how to speed that up. Most likey, we'll need to cut down on bundlesize.

Suggestions for registry sidebar

Existing registry sidebar:

Screen Shot 2021-10-27 at 9 22 09 am

Here are some ideas on how this might be improved:

  • add a 'search' input to filter down the list (this will be helpful as the registry grows)
  • Would it make sense to put packages in a @namespace in their own sections?
  • Should namedspaced packages (eg @atlaskit/avatar) have the @ prefix?

FIX: CLI!!!!!!!!!

npx: installed 277 in 28.244s
⨯ Unable to compile TypeScript:
error TS5083: Cannot read file '/Users/ddelcore/.npm/_npx/14325/lib/node_modules/tsconfig.json'.

🛝 Config specification

codeshift.config.ts is intended to act as the source of truth for every codemod package. Configs serve a dual purpose of holding all relevant metadata and one or more codemods.

Config properties

  • maintainers: Github maintainer usernames to be pinged when an issue/pr is raised against a mod
  • description: Description of the package
  • target: Packages to target. This will be used by the github bot to trigger codemod runs in the future
  • transforms: Key-value pair of transforms organised by semver version. These are indented for package targeting
  • presets: Generic transforms that are related to the package

Example:

export default {
  maintainers: ['danieldelcore'],
  description: "Codemods for upgrading @atlaskit/avatar",
  target: ["@atlaskit/avatar", "@atlaskit/avatar-group"],
  transforms: {
    // Transforms for migrating to v1 of atlaskit avatar
    "1.0.0": require("./1.0.0/transform"), 
    "2.0.0": require("./2.0.0/transform"), 
  },
  presets: {
    // Generic codemods intended to support the use of @atlaskit/avatar
    "remove-chilren-props": require("./remove-chilren-props/transform"),
  },
};

There are two types of codemods:

  • transforms these are intended to move a package on NPM across versions. (v1->v2)
  • presets intended to support the package (remove deprecated api)

Problems

  • With the separation of versioned codemods, and presets is a bit odd. Ideally we can flatten this structure a bit more

Generic codemods

There are a lot of codemods that are written for general use.
Consider "sort imports", "convert to arrow function" etc

These should have a home in this repo too for people who might find them useful.

My suggestion is to provide a preset folder which behaves similarly to the community folder, but without the restrictions on file names etc.

consider forking jscodeshift

at this point i'm reaching the boundaries of what can be done w/ this, without modifying the source code of jscodeshift itself.

it would be very benefitial to have a fork that we use directly.

i've done this a lot already - you fork the repository into your org, and add it here as a git submodule.
some build steps will need to be updated, but otherwise we'd be able to maintain our fork of jscodeshift, work out whatever behavior we want, and then even submit patches upstream (exactly what i'm doing now, but one level lower:D)

wdyt? myself need this a lot.

Support codemodding CSS via PostCSS

Codeshift should be extended to support modules that have APIs that span across JS and CSS.

The idea is that a library maintainer can ship an API change to their library that affects both JS and CSS. This codemod would then be configured to run a transform for both environments.

Unfortunately JSCodehsift + Recast aren't designed to do that, however we can substitute other parsers like PostCSS as options.

https://twitter.com/danieldelcore/status/1496718163714576386?s=20&t=v4nUru6h12nyrnt6M88TKA

A config could look something like this:

{
  module.exports = {
    transforms: {
    "10.0.0": {
      "js,jsx,tsx,ts": require.resolve("./10.0.0/transform")
      "css,sass,scss":  require.resolve("./10.0.0/transform/css")
     },
};

These extensions would be globs/regex that would match file extensions and apply a different codemod as a result.
These would be paired with custom parsers that would be "part" of the codeshift library.

import { FileInfo } from 'jscodeshift';
import postcss, { Node, Rule, Declaration, Plugin } from 'postcss';
import lessSyntax from 'postcss-less';

// https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
// https://astexplorer.net/#/2uBU1BLuJ1
const plugin = (): Plugin => {
  const processed = Symbol('processed');

  return {
    postcssPlugin: 'UsingTokens',
    Declaration: (decl) => {
      // @ts-expect-error
      if (decl[processed]) {
        return;
      }

      // Transformation goes here

      decl[processed] = true;
    },
  };
};

export default async function transformer(file: FileInfo) {
  return await postcss([plugin()]).process(file.source, { syntax: lessSyntax })
    .css;
}

facebook/jscodeshift#124

Take a look at codemod-cli

Scanning npm for packages about codemods I have found codemod-cli:
https://www.npmjs.com/package/codemod-cli

It looks like a tool to create and manage collections of codemods. It takes care of:

  • creating a new project, which includes a CLI to easily execute the codemods as a standalone CLI tool
  • adding new codemods to the project, having an specific folder structure (that I find interesting)
  • testing the codemods
  • updating the documentation. Not sure how it does it, but I am pretty sure it picks the input and output fixtures to generate the examples

Maybe you should consider contacting the author and talk him about the codeshift community, or at least add it to the resources section?

Feature: Allow adding a TS 4.5 style type import

I'm trying to write a codemod that changes from the old style of type imports:

import type {MyType} from './types';

to the newer style:

import {type MyType} from './types';

I saw you have some import helpers, but don't see anything that allows creation of an ImportSpecifier with importKind: "type", which I think is what is needed. Maybe you could consider adding it?

Thanks!

Docs for finding descendants

For example finding the nearest CallExpression

function isDecendantOfToken(path: any) {
  if (!path.parentPath) {
    return false;
  }

  if (
    path.parentPath.value.type === 'CallExpression' &&
    path.parentPath.value.callee.name === 'token'
  ) {
    return true;
  }

  return path.parentPath;
}

Fix dependency bundling

Currently dependencies bundled with codemods are not accessible due to jscodeshift being unable to run codemods as functions.

We may need to fork jscodeshift or hack around it so that we can pass bundled codemods into it and fix our dependency issues.

For example, this command will break when run outside of the main repo: npx @codeshift/[email protected] --packages @atlaskit/[email protected] packages

Should list local codeshift.config transforms when no packages or transforms provided

For local development, we should list local codeshift.config transforms when no packages or transforms provided.

This would work by:

  • Searching a few known locations for a codeshift.config
  • Listing those options as an interactive selection list
  • And running them

Make sure to also upgrade the default testing commands in the project template (ie codeshift init)

CLI init command should not require a version

The init command should not require a version upfront. Instead that flag should be optional. If the version isn't specified, make sure a "commented" version of a config is output to give users a quick starting point.

Rename 'Explore' on website?

It wasn't clear to me that the codemod registry was under the 'explore' tab (maybe it's just me!)

Here are some alternatives:

  • 'Codemods'
  • 'Registry'
  • 'Codemod registry'

CLI to support init for external codemods

Allow for initialisation of new packages outside of the community repo with the CLI.

Outputting a clean and valid file structure / configuration that is ready to be published

Great initiative and may need public forums?

Thanks a lot for creating this community, it is a great start to spread awareness about codemods and automated migration tools.
Being a codemod author brings joy to see these kind of initiatives from the community. Does it make sense to have a forum in Slack or Discord for the community to get help, discuss and build codemods or is it too early?

I leave the timelines to you folks since you are the best people to make the decisions. Thanks once again and would be glad to help in anyway possible.

Split CLI package into node and cli

JSCodeshift currently only provides a CLI API which is problematic for people who would like to build on top of it to provide, for example, a customised CLI with additional features etc (like what we're hoping to do with this project)

We should investigate either using import * as jscodeshift from 'jscodeshift/src/Runner'; or fork jscodeshift to and mould it into something more official.

Related issues:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.