Skip to content

Commit 5028a96

Browse files
Merge pull request #5240 from NativeScript/vladimirov/merge-rel-master
chore: merge release in master
2 parents 8e29a44 + 5a99bf3 commit 5028a96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+279
-136
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ NativeScript CLI Changelog
1616
### Fixed
1717

1818
* [Fixed #5187](https://github.com/NativeScript/nativescript-cli/issues/5187): Inaccessible native source code without modulemap
19+
* [Fixed #5239](https://github.com/NativeScript/nativescript-cli/issues/5239): Temporary files created by CLI are not deleted in some cases
1920

2021

2122
6.3.3 (2020, January 13)

lib/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,4 @@ $injector.require("ipService", "./services/ip-service");
236236
$injector.require("jsonFileSettingsService", "./common/services/json-file-settings-service");
237237
$injector.require("markingModeService", "./services/marking-mode-service");
238238
$injector.require("metadataFilteringService", "./services/metadata-filtering-service");
239+
$injector.require("tempService", "./services/temp-service");

lib/commands/plugin/build-plugin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EOL } from "os";
22
import * as path from "path";
33
import * as constants from "../../constants";
4-
import * as temp from "temp";
4+
55
export class BuildPluginCommand implements ICommand {
66
public allowedParameters: ICommandParameter[] = [];
77
public pluginProjectPath: string;
@@ -10,7 +10,8 @@ export class BuildPluginCommand implements ICommand {
1010
private $errors: IErrors,
1111
private $logger: ILogger,
1212
private $fs: IFileSystem,
13-
private $options: IOptions) {
13+
private $options: IOptions,
14+
private $tempService: ITempService) {
1415

1516
this.pluginProjectPath = path.resolve(this.$options.path || ".");
1617
}
@@ -29,8 +30,7 @@ export class BuildPluginCommand implements ICommand {
2930
}
3031
}
3132

32-
temp.track();
33-
const tempAndroidProject = temp.mkdirSync("android-project");
33+
const tempAndroidProject = await this.$tempService.mkdirSync("android-project");
3434

3535
const options: IPluginBuildOptions = {
3636
aarOutputDir: platformsAndroidPath,

lib/common/mobile/android/android-device-file-system.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as path from "path";
22
import * as semver from "semver";
3-
import * as temp from "temp";
43
import { AndroidDeviceHashService } from "./android-device-hash-service";
54
import { executeActionByChunks } from "../../helpers";
65
import { DEFAULT_CHUNK_SIZE } from '../../constants';
@@ -12,6 +11,7 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
1211
private $fs: IFileSystem,
1312
private $logger: ILogger,
1413
private $mobileHelper: Mobile.IMobileHelper,
14+
private $tempService: ITempService,
1515
private $injector: IInjector) { }
1616

1717
public async listFiles(devicePath: string, appIdentifier?: string): Promise<any> {
@@ -27,8 +27,7 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
2727
const stdout = !outputPath;
2828

2929
if (stdout) {
30-
temp.track();
31-
outputPath = temp.path({ prefix: "sync", suffix: ".tmp" });
30+
outputPath = await this.$tempService.path({ prefix: "sync", suffix: ".tmp" });
3231
}
3332

3433
await this.adb.executeCommand(["pull", deviceFilePath, outputPath]);
@@ -134,7 +133,7 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
134133
}
135134

136135
public async createFileOnDevice(deviceFilePath: string, fileContent: string): Promise<void> {
137-
const hostTmpDir = this.getTempDir();
136+
const hostTmpDir = await this.$tempService.mkdirSync("application-");
138137
const commandsFileHostPath = path.join(hostTmpDir, "temp.commands.file");
139138
this.$fs.writeFile(commandsFileHostPath, fileContent);
140139

@@ -159,9 +158,4 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
159158

160159
return this._deviceHashServices[appIdentifier];
161160
}
162-
163-
private getTempDir(): string {
164-
temp.track();
165-
return temp.mkdirSync("application-");
166-
}
167161
}

lib/common/mobile/android/android-device-hash-service.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from "path";
2-
import * as temp from "temp";
32
import { cache } from "../../decorators";
43
import { executeActionByChunks } from "../../helpers";
54
import { DEFAULT_CHUNK_SIZE, LiveSyncPaths } from "../../constants";
@@ -10,7 +9,8 @@ export class AndroidDeviceHashService implements Mobile.IAndroidDeviceHashServic
109
constructor(private adb: Mobile.IDeviceAndroidDebugBridge,
1110
private appIdentifier: string,
1211
private $fs: IFileSystem,
13-
private $mobileHelper: Mobile.IMobileHelper) {
12+
private $mobileHelper: Mobile.IMobileHelper,
13+
private $tempService: ITempService) {
1414
}
1515

1616
@cache()
@@ -34,8 +34,9 @@ export class AndroidDeviceHashService implements Mobile.IAndroidDeviceHashServic
3434
}
3535

3636
public async uploadHashFileToDevice(data: IStringDictionary): Promise<void> {
37-
this.$fs.writeJson(this.hashFileLocalPath, data);
38-
await this.adb.pushFile(this.hashFileLocalPath, this.hashFileDevicePath);
37+
const hashFileLocalPath = await this.getHashFileLocalPath();
38+
this.$fs.writeJson(hashFileLocalPath, data);
39+
await this.adb.pushFile(hashFileLocalPath, this.hashFileDevicePath);
3940
}
4041

4142
public async updateHashes(localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void> {
@@ -86,20 +87,20 @@ export class AndroidDeviceHashService implements Mobile.IAndroidDeviceHashServic
8687
}
8788

8889
@cache()
89-
private get hashFileLocalPath(): string {
90-
return path.join(this.tempDir, AndroidDeviceHashService.HASH_FILE_NAME);
90+
private async getHashFileLocalPath(): Promise<string> {
91+
return path.join(await this.getTempDir(), AndroidDeviceHashService.HASH_FILE_NAME);
9192
}
9293

9394
@cache()
94-
private get tempDir(): string {
95-
temp.track();
96-
return temp.mkdirSync(`android-device-hash-service-${this.appIdentifier}`);
95+
private getTempDir(): Promise<string> {
96+
return this.$tempService.mkdirSync(`android-device-hash-service-${this.appIdentifier}`);
9797
}
9898

9999
private async downloadHashFileFromDevice(): Promise<string> {
100-
if (!this.$fs.exists(this.hashFileLocalPath)) {
101-
await this.adb.executeCommand(["pull", this.hashFileDevicePath, this.tempDir]);
100+
const hashFileLocalPath = await this.getHashFileLocalPath();
101+
if (!this.$fs.exists(hashFileLocalPath)) {
102+
await this.adb.executeCommand(["pull", this.hashFileDevicePath, await this.getTempDir()]);
102103
}
103-
return this.hashFileLocalPath;
104+
return hashFileLocalPath;
104105
}
105106
}

lib/common/mobile/ios/simulator/ios-simulator-application-manager.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { hook, getPidFromiOSSimulatorLogs } from "../../../helpers";
44
import { cache } from "../../../decorators";
55
import { IOS_LOG_PREDICATE } from "../../../constants";
66
import * as path from "path";
7-
import * as temp from "temp";
87
import * as log4js from "log4js";
98

109
export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
@@ -16,6 +15,7 @@ export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
1615
private $options: IOptions,
1716
private $fs: IFileSystem,
1817
protected $deviceLogProvider: Mobile.IDeviceLogProvider,
18+
private $tempService: ITempService,
1919
$logger: ILogger,
2020
$hooksService: IHooksService) {
2121
super($logger, $hooksService, $deviceLogProvider);
@@ -28,8 +28,7 @@ export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
2828
@hook('install')
2929
public async installApplication(packageFilePath: string): Promise<void> {
3030
if (this.$fs.exists(packageFilePath) && path.extname(packageFilePath) === ".zip") {
31-
temp.track();
32-
const dir = temp.mkdirSync("simulatorPackage");
31+
const dir = await this.$tempService.mkdirSync("simulatorPackage");
3332
await this.$fs.unzip(packageFilePath, dir);
3433
const app = _.find(this.$fs.readDirectory(dir), directory => path.extname(directory) === ".app");
3534
if (app) {

lib/common/mobile/mobile-helper.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as helpers from "../helpers";
22
import * as shell from "shelljs";
3-
import * as temp from "temp";
43

54
export class MobileHelper implements Mobile.IMobileHelper {
65
private static DEVICE_PATH_SEPARATOR = "/";
76

87
constructor(private $errors: IErrors,
98
private $fs: IFileSystem,
10-
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
9+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
10+
private $tempService: ITempService) { }
1111

1212
public get platformNames(): string[] {
1313
return [this.$devicePlatformsConstants.iOS, this.$devicePlatformsConstants.Android];
@@ -58,8 +58,7 @@ export class MobileHelper implements Mobile.IMobileHelper {
5858
}
5959

6060
public async getDeviceFileContent(device: Mobile.IDevice, deviceFilePath: string, projectData: IProjectData): Promise<string> {
61-
temp.track();
62-
const uniqueFilePath = temp.path({ suffix: ".tmp" });
61+
const uniqueFilePath = await this.$tempService.path({ suffix: ".tmp" });
6362
const platform = device.deviceInfo.platform.toLowerCase();
6463
try {
6564
await device.fileSystem.getFile(deviceFilePath, projectData.projectIdentifiers[platform], uniqueFilePath);

lib/common/test/unit-tests/mobile/android-device-file-system.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DevicePlatformsConstants } from "../../../mobile/device-platforms-const
88
import * as path from "path";
99
import { assert } from "chai";
1010
import { LiveSyncPaths } from "../../../constants";
11+
import { TempServiceStub } from "../../../../../test/stubs";
1112

1213
const myTestAppIdentifier = "org.nativescript.myApp";
1314
let isAdbPushExecuted = false;
@@ -64,7 +65,7 @@ function createTestInjector(): IInjector {
6465
injector.register("errors", Errors);
6566
injector.register("devicePlatformsConstants", DevicePlatformsConstants);
6667
injector.register("projectFilesManager", {});
67-
68+
injector.register("tempService", TempServiceStub);
6869
return injector;
6970
}
7071

lib/common/test/unit-tests/mobile/ios-simulator-discovery.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { assert } from "chai";
55
import { DeviceDiscoveryEventNames, CONNECTED_STATUS } from "../../../constants";
66
import { DevicePlatformsConstants } from "../../../mobile/device-platforms-constants";
77
import { ErrorsStub, CommonLoggerStub, HooksServiceStub, LockServiceStub } from "../stubs";
8-
import { FileSystemStub, ChildProcessStub } from "../../../../../test/stubs";
8+
import { FileSystemStub, ChildProcessStub, TempServiceStub } from "../../../../../test/stubs";
99
import { DeviceConnectionType } from "../../../../constants";
1010

1111
let currentlyRunningSimulators: Mobile.IiSimDevice[];
@@ -45,7 +45,7 @@ function createTestInjector(): IInjector {
4545
injector.register("options", {});
4646
injector.register("hooksService", HooksServiceStub);
4747
injector.register("logger", CommonLoggerStub);
48-
48+
injector.register("tempService", TempServiceStub);
4949
return injector;
5050
}
5151

lib/common/test/unit-tests/mobile/project-files-manager.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ProjectFilesProviderBase } from "../../../services/project-files-provid
1414

1515
import temp = require("temp");
1616
import { LiveSyncPaths } from "../../../constants";
17+
import { TempServiceStub } from "../../../../../test/stubs";
1718
temp.track();
1819

1920
const testedApplicationIdentifier = "com.telerik.myApp";
@@ -49,6 +50,7 @@ function createTestInjector(): IInjector {
4950
});
5051
testInjector.register("logger", Logger);
5152
testInjector.register("config", {});
53+
testInjector.register("tempService", TempServiceStub);
5254
return testInjector;
5355
}
5456

lib/definitions/ios.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ declare global {
3030
}
3131

3232
interface IExportOptionsPlistService {
33-
createDevelopmentExportOptionsPlist(archivePath: string, projectData: IProjectData, buildConfig: IBuildConfig): IExportOptionsPlistOutput;
34-
createDistributionExportOptionsPlist(projectRoot: string, projectData: IProjectData, buildConfig: IBuildConfig): IExportOptionsPlistOutput;
33+
createDevelopmentExportOptionsPlist(archivePath: string, projectData: IProjectData, buildConfig: IBuildConfig): Promise<IExportOptionsPlistOutput>;
34+
createDistributionExportOptionsPlist(projectRoot: string, projectData: IProjectData, buildConfig: IBuildConfig): Promise<IExportOptionsPlistOutput>;
3535
}
3636

3737
interface IExportOptionsPlistOutput {

lib/definitions/plugins.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface IPluginsService {
44
addToPackageJson(plugin: string, version: string, isDev: boolean, projectDir: string): void;
55
removeFromPackageJson(plugin: string, projectDir: string): void;
66
getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]>;
7-
getAllProductionPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): IPluginData[];
7+
getAllProductionPlugins(projectData: IProjectData, platform: string, dependencies?: IDependencyData[]): IPluginData[];
88
ensureAllDependenciesAreInstalled(projectData: IProjectData): Promise<void>;
99

1010
/**

lib/definitions/temp-service.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Declares wrapped functions of temp module
3+
*/
4+
interface ITempService {
5+
mkdirSync(affixes: string): Promise<string>;
6+
path(options: ITempPathOptions): Promise<string>;
7+
}

lib/device-sockets/ios/app-debug-socket-proxy-factory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { EventEmitter } from "events";
22
import { CONNECTION_ERROR_EVENT_NAME } from "../../constants";
33
import * as net from "net";
44
import * as ws from "ws";
5-
import temp = require("temp");
65
import { MessageUnpackStream } from "ios-device-lib";
76

87
export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebugSocketProxyFactory {
@@ -13,6 +12,7 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
1312
private $errors: IErrors,
1413
private $lockService: ILockService,
1514
private $options: IOptions,
15+
private $tempService: ITempService,
1616
private $net: INet) {
1717
super();
1818
}
@@ -72,7 +72,7 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
7272
frontendSocket.resume();
7373
});
7474

75-
const socketFileLocation = temp.path({ suffix: ".sock" });
75+
const socketFileLocation = await this.$tempService.path({ suffix: ".sock" });
7676
server.listen(socketFileLocation);
7777
if (!this.$options.client) {
7878
this.$logger.info("socket-file-location: " + socketFileLocation);

lib/helpers/platform-command-helper.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as path from "path";
22
import * as semver from "semver";
3-
import * as temp from "temp";
43
import * as constants from "../constants";
54
import { PlatformController } from "../controllers/platform-controller";
65
import { PlatformValidationService } from "../services/platform/platform-validation-service";
@@ -17,7 +16,8 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
1716
private $platformsDataService: IPlatformsDataService,
1817
private $platformValidationService: PlatformValidationService,
1918
private $projectChangesService: IProjectChangesService,
20-
private $projectDataService: IProjectDataService
19+
private $projectDataService: IProjectDataService,
20+
private $tempService: ITempService
2121
) { }
2222

2323
public async addPlatforms(platforms: string[], projectData: IProjectData, frameworkPath: string): Promise<void> {
@@ -147,7 +147,7 @@ export class PlatformCommandHelper implements IPlatformCommandHelper {
147147
const data = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
148148
const currentVersion = data && data.version ? data.version : "0.2.0";
149149

150-
const installedModuleDir = temp.mkdirSync("runtime-to-update");
150+
const installedModuleDir = await this.$tempService.mkdirSync("runtime-to-update");
151151
let newVersion = version === constants.PackageVersion.NEXT ?
152152
await this.$packageInstallationManager.getNextVersion(platformData.frameworkPackageName) :
153153
version || await this.$packageInstallationManager.getLatestCompatibleVersion(platformData.frameworkPackageName);

lib/services/ios-project-service.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { attachAwaitDetach } from "../common/helpers";
77
import * as projectServiceBaseLib from "./platform-project-service-base";
88
import { PlistSession, Reporter } from "plist-merge-patch";
99
import { EOL } from "os";
10-
import * as temp from "temp";
1110
import * as plist from "plist";
1211
import { IOSProvisionService } from "./ios-provision-service";
1312
import { IOSEntitlementsService } from "./ios-entitlements-service";
@@ -55,7 +54,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
5554
private $iOSExtensionsService: IIOSExtensionsService,
5655
private $iOSWatchAppService: IIOSWatchAppService,
5756
private $iOSNativeTargetService: IIOSNativeTargetService,
58-
private $sysInfo: ISysInfo) {
57+
private $sysInfo: ISysInfo,
58+
private $tempService: ITempService) {
5959
super($fs, $projectDataService);
6060
}
6161

@@ -471,7 +471,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
471471
}
472472

473473
private getAllProductionPlugins(projectData: IProjectData): IPluginData[] {
474-
return (<IPluginsService>this.$injector.resolve("pluginsService")).getAllProductionPlugins(projectData);
474+
return (<IPluginsService>this.$injector.resolve("pluginsService")).getAllProductionPlugins(projectData, this.getPlatformData(projectData).platformNameLowerCase);
475475
}
476476

477477
private replace(name: string): string {
@@ -814,8 +814,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
814814
// Set Entitlements Property to point to default file if not set explicitly by the user.
815815
const entitlementsPropertyValue = this.$xcconfigService.readPropertyValue(pluginsXcconfigFilePath, constants.CODE_SIGN_ENTITLEMENTS);
816816
if (entitlementsPropertyValue === null && this.$fs.exists(this.$iOSEntitlementsService.getPlatformsEntitlementsPath(projectData))) {
817-
temp.track();
818-
const tempEntitlementsDir = temp.mkdirSync("entitlements");
817+
const tempEntitlementsDir = await this.$tempService.mkdirSync("entitlements");
819818
const tempEntitlementsFilePath = path.join(tempEntitlementsDir, "set-entitlements.xcconfig");
820819
const entitlementsRelativePath = this.$iOSEntitlementsService.getPlatformsEntitlementsRelativePath(projectData);
821820
this.$fs.writeFile(tempEntitlementsFilePath, `CODE_SIGN_ENTITLEMENTS = ${entitlementsRelativePath}${EOL}`);

0 commit comments

Comments
 (0)