Skip to content

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

Closed as not planned

Description

@sis0k0

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

Activity

  1. NathanWalker commented on Oct 23, 2026

    @NathanWalker
    Contributor

    Closing as obsolete: the move from tns-core-modules to @nativescript/core is long complete, and the migration tooling (ns migrate) handles imports for remaining projects. Thanks for the detailed spec!

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

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