Skip to content

Commit c1c3ac4

Browse files
authored
Flatten scoped module when copying into android/src (#2837)
* fix path when removing dir in a scoped dependency during prepare * flatten android plugins with native code when copying into main/src
1 parent ab08c91 commit c1c3ac4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/services/android-project-service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
361361
if (this.$fs.exists(pluginPlatformsFolderPath)) {
362362
this.$fs.ensureDirectoryExists(pluginConfigurationDirectoryPath);
363363

364+
let isScoped = pluginData.name.indexOf("@") === 0;
365+
let flattenedDependencyName = isScoped ? pluginData.name.replace("/", "_") : pluginData.name;
366+
364367
// Copy all resources from plugin
365-
let resourcesDestinationDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, "src", pluginData.name);
368+
let resourcesDestinationDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, "src", flattenedDependencyName);
366369
this.$fs.ensureDirectoryExists(resourcesDestinationDirectoryPath);
367370
shell.cp("-Rf", path.join(pluginPlatformsFolderPath, "*"), resourcesDestinationDirectoryPath);
368371

lib/tools/node-modules/node-modules-dest-copy.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,20 @@ export class TnsModulesCopy {
3636

3737
private copyDependencyDir(dependency: IDependencyData): void {
3838
if (dependency.depth === 0) {
39+
const targetPackageDir = path.join(this.outputRoot, dependency.name);
40+
41+
shelljs.mkdir("-p", targetPackageDir);
42+
3943
let isScoped = dependency.name.indexOf("@") === 0;
40-
let targetDir = this.outputRoot;
4144

4245
if (isScoped) {
43-
targetDir = path.join(this.outputRoot, dependency.name.substring(0, dependency.name.indexOf("/")));
46+
// copy module into tns_modules/@scope/module instead of tns_modules/module
47+
shelljs.cp("-Rf", dependency.directory, path.join(this.outputRoot, dependency.name.substring(0, dependency.name.indexOf("/"))));
48+
} else {
49+
shelljs.cp("-Rf", dependency.directory, this.outputRoot);
4450
}
4551

46-
shelljs.mkdir("-p", targetDir);
47-
shelljs.cp("-Rf", dependency.directory, targetDir);
48-
49-
//remove platform-specific files (processed separately by plugin services)
50-
const targetPackageDir = path.join(targetDir, dependency.name);
52+
// remove platform-specific files (processed separately by plugin services)
5153
shelljs.rm("-rf", path.join(targetPackageDir, "platforms"));
5254
}
5355
}

0 commit comments

Comments
 (0)