Shared files/classes with symlinks in project folders?

Hi there,

I got three folders side by side: The first one is a “common” folder, the second and third one is an Ionic project folder. I tried to symlink with mklink /D services ..\..\common\services\ a symbolic link called services.

At the first look everything seems nice and dandy when I check the path handlings over the console. But at building time I get errors corresponding to not existing @angular- or @ionic-libraries, because of compiling in the real common-folder, where no node folder exists …

In the past I remember an argument ng serve --preserve-symlinks but at today versions it seems to be gone …

Anyone had practical experiences with shared classes in different Ionic projects?

Fyi, here’s an example of one of these shared common classes:

File debugService.ts

import { Injectable } from '@angular/core';
// ERROR: Over a symlink it tries to find @angular in ../../common/services
// but it should look into the services folder of the actual ionic project folder :/

@Injectable()
export class DebugService {
  public isActive: boolean = true;
  public debugRoles: DebugRoleEnum[] = [
    DebugRoleEnum.myFirstRole,
    DebugRoleEnum.mySecondRole,
  ];
  log(debugRole: DebugRoleEnum, ...messages) { if (this.debugRoles.indexOf(debugRole) > -1) console.log(DebugRoleEnum[debugRole], messages); }
}

export enum DebugRoleEnum {
  myFirstRole,
  mySecondRole,
  myThirdRole,
  myAnotherRole,
}

Yes, it’s just a simple injected class …

Thank you for any help :slight_smile:

If you don’t get any better answers, I am reminded of the joke about the person who goes to the doctor complaining that “it hurts when I do this”, and receives the advice “don’t do that, then”.

It’s a great benefit, especially when factoring in things like CI, to be able to build your ionic app from absolute scratch in a new build environment as simply and automatically as possible, and sharing code via symlinks throws a huge wrench into that process.

There are a bunch of ways to create and reference private npm packages and repositories, and I would suggest investigating those, so that your shared code can be an npm dependency like any other third-party library you’re using.

Thanks rapropos! There must be a bunch of ways doin’ it with npm … the “simple” way with symlinks was intuitively chosen as I don’t know much about npm but installing some packages, actually.

You seem to know much about npm and sharing files/packages the right way. Could you share one example from that bunch of ways if you don’t mind? Definitely it could help me (and perhaps others) out.

Big thanks :v:

Check out the mentions of “git”-related stuff in the npm install manpage. If you arrange your shared stuff as an npm module (look at the package.json of any of the existing dependencies your app has to see some examples of how to make those, along with the official npm docs), you can host it either locally, or on a published repo like GitLab, GitHub, or even NPM itself, and using a git-style NPM dependency url, npm will delegate the fetching to git.