npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ota-insight/ember-computed-macro-codemod

v0.1.0

Published

A codemod for converting Ember computed property macros (a.k.a. shorthands) to native getters in class syntax

Downloads

2

Readme

ember-computed-macro-codemod

A codemod for converting Ember computed property macros (a.k.a. shorthands) to native getters in class syntax.

Updating your codebase

The recommended Ember ESLint config discourages computed property macros for class based syntax. Instead, it recommends to use auto tracking and native getters. This codemod converts a subset (see support matrix) of all computed property macros to native getters.

See also:

  • This codemod only runs on JavaScript Class syntax. If you haven't already, use the ember-native-class codemod to transform object syntax to class syntax.
  • The ember-tracked-properties codemod will further help you migrate from @computed to tracked properties.

Usage

npx @ota-insight/ember-computed-macro-codemod path/of/files/ or/some**/*glob.js

Warning As with most codemods, changes are made in place, meaning it will overwrite existing files. Make sure to run this codemod on a codebase that has been checked into version control to avoid losing progress.

The codemod accepts the following options:

| Option | Value | Default | Details | | --------------------- | ------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | | --macros | string | alias,and,equal,gt,gte,lt,lte,or,readOnly | Filter which computed macros should be transformed. By default, all supported ones are transformed. | | --add-computed-decorator | boolean | false | Add the @computed decorator to the native getter for full compatibility. Skipping this has sublte side effects which could cause issues.1 |

1. Computed property macros are computed properties, thus only recompute once the dependency keys are updated. If you want to keep this behaviour, the @cached decorator should be added. This should however be used with caution, and is usually something you don't want. (see docs) Alternatively, you can opt to readd the @computed decorator to keep compatible behaviour in case where not all dependencies are auto tracked yet.

Basic example

Given the following input file:

import { readOnly } from '@ember/object/computed';

class Foo {
  @readOnly('foo.bar') bar;
}

The codemod will rewrite this to use native getters:

class Foo {
  get bar() {
    return this.foo?.bar;
  }
}

For a complete list of example transforms, see the computed-macro transform description.

Support matrix

| Computed property macro | Supported | |------------------|-----------| | alias | ✅ | | and | ✅ | | bool | ❌ | | collect | ❌ | | deprecatingAlias | ❌ | | empty | ❌ | | equal | ✅ | | expandProperties | ❌ | | filter | ❌ | | filterBy | ❌ | | gt | ✅ | | gte | ✅ | | intersect | ❌ | | lt | ✅ | | lte | ✅ | | map | ❌ | | mapBy | ❌ | | match | ❌ | | max | ❌ | | min | ❌ | | not | ❌ | | notEmpty | ❌ | | oneWay | ❌ | | or | ✅ | | readOnly | ✅ | | reads | ❌ | | setDiff | ❌ | | sort | ❌ | | sum | ❌ | | union | ❌ | | uniq | ❌ | | uniqBy | ❌ |

Known limitations

  • Computed property macros with complex dependent keys are not supported (@each, .{}, .[]).
  • Doesn't handle invalid usages of marcos, e.g. using and, or with only one argument.
  • Expects you import computed macros from @ember/object/computed, instead of e.g. using @computed.readOnly().

Transforms

Contributing

Installation

  • clone the repo
  • change into the repo directory
  • yarn

Running tests

  • yarn test

Update Documentation

  • yarn update-docs