Skip to content

Create an ESLint rule for migrating to scoped packages imports #8131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sis0k0 opened this issue Nov 21, 2019 · 0 comments
Open

Create an ESLint rule for migrating to scoped packages imports #8131

sis0k0 opened this issue Nov 21, 2019 · 0 comments

Comments

@sis0k0
Copy link
Contributor

sis0k0 commented Nov 21, 2019

Why?

Provide an automated way to migrate imports and require statements from:

  • tns-core-modules to @nativescript/core;
  • and nativescript-angular to @nativescript/angular.

How?

The above can be achieved by providing an ESLint rule that detects the old type of imports and recommends using the new one. It should also provide an autofix that migrates the imports.

Migration description

JS/TS

The rule should work for both JS and TS projects.

tns-core-modules -> @nativescript/core

The rule should migrate the imports from that package in the following way:

for imports from application, application-settings, connectivity, image-asset, trace:

  1. import { run } from "tns-core-modules/application" ->
    import { Application } from "@nativescript/core"
  2. const run = require("tns-core-modules/application").run ->
    const Application = require("@nativescript/core/application")

In cases 1 and 2, the rule should also change all uses of run in the code to Application.run.

  1. import * as application from "tns-core-modules/application" ->
    import { Application } from "@nativescript/core"
  2. const application = require("tns-core-modules/application") ->
    const Application = require("@nativescript/core").Application

In cases 3 and 4, the rule should also change all uses of application in the code to Application.

for imports from utils/utils:

The same as application with this exception:

import * as utils from "tns-core-modules/utils/utils";
utils.ad;
->
import { Utils } from "@nativescript/core";
Utils.android;
`

for imports from profiling:

Migrate to import { Profiling } from @nativescript/core for the methods that are now exported through the Profiling constant from @nativescript/core:

export const Profiling = {
enable: profilingEnable,
disable: profilingDisable,
time, uptime,
start, stop, isRunning,
dumpProfiles, resetProfiles,
profile, startCPUProfile, stopCPUProfile,
};

Migrate to import { SomeInterface } from '@nativescript/core' for all symbols that are now directly exported from @nativescript/core:

export { InstrumentationMode, TimerInfo } from "./profiling";

for imports from trace:

Migrate to import { Trace } from @nativescript/core for the methods that are now exported through the Trace constant from @nativescript/core:

export const Trace = {
messageType, categories, setCategories, addCategories,
addWriter, removeWriter, clearWriters,
setErrorHandler,
write, error, enable, disable, isEnabled
};

Migrate to import { SomeInterface } from '@nativescript/core' for all symbols that are now directly exported from @nativescript/core:

export { DefaultErrorHandler, ErrorHandler, TraceWriter } from "./trace";

for imports from http:

Migrate to import { Http } from @nativescript/core for the methods that are now exported through the Http constant from @nativescript/core:

export const Http = { getFile, getImage, getJSON, getString: httpGetString, request };

Migrate to import { SomeInterface } from '@nativescript/core' for all symbols that are now directly exported from @nativescript/core:
export { HttpRequestOptions, HttpResponse, Headers, HttpResponseEncoding, HttpContent } from "./http";

for imports from platform:

For isAndroid and isIOS migrate to @nativescript/core.
For screen and device migrate to import { Screen, Device } from '@nativescript/core';.
For any other path migrate to @nativescript/core/platform.

for imports from ui/*, data/observable-array, data/observable, file-system, color, image-asset, image-source, text, xml:

  1. import { Observable } from "tns-core-modules/data/observable" ->
    import { Observable } from "@nativescript/core"
  2. const Observable = require("tns-core-modules/data/observable") ->
    const Observable = require("@nativescript/core").Observable

for every other import starting with tns-core-modules, the tns-core-modules prefix should be replaced with @nativescript/core.

nativescript/angular -> @nativescript/angular

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants