Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@sis0k0

Description

@sis0k0
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.